aboutsummaryrefslogtreecommitdiffstats
path: root/lib/wretch.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-02-21 17:05:14 -0800
committerAdam Soltys <[email protected]>2023-02-21 17:05:14 -0800
commit94f8e7a27cdc5922919d85d8051d24ada1f06922 (patch)
treea646b8dd608e1a3b195efe1dc2848106ca3d5a47 /lib/wretch.js
parent2346e4824a406d6cb797a034d91bb5d1b321bbfc (diff)
downloadcoinos-server-94f8e7a27cdc5922919d85d8051d24ada1f06922.tar.gz
coinos-server-94f8e7a27cdc5922919d85d8051d24ada1f06922.zip
catch payment failure
Diffstat (limited to 'lib/wretch.js')
0 files changed, 0 insertions, 0 deletions
Blame the previous revision' href='/coinos-server.git/blame/routes/users.coffee?h=tickets&id=7f19424e402be418d18b77dab06f263ef450a146'>^
60f21d29 ^
15cf6c4e ^
60f21d29 ^



74978738 ^
3407774b ^

15cf6c4e ^
40083923 ^





74978738 ^


15cf6c4e ^
8e2f50f4 ^
8426aa8e ^
15cf6c4e ^
561ab2d0 ^



8426aa8e ^
86d32113 ^
8426aa8e ^

a50564c1 ^
c1cd5515 ^
41f8c683 ^
c1cd5515 ^

9d4926c9 ^

c1cd5515 ^

8426aa8e ^

8e2f50f4 ^
514b869f ^
561ab2d0 ^



514b869f ^
74978738 ^


60029a8f ^
561ab2d0 ^
60029a8f ^

74978738 ^
5c5ae752 ^
74978738 ^
3b565f4f ^
99b32961 ^

ed4a64c6 ^
e547723b ^
3b565f4f ^
e547723b ^








ed4a64c6 ^
8426aa8e ^
e547723b ^





329798f4 ^

e547723b ^







3de0e94e ^





15ee6390 ^
3de0e94e ^
3407774b ^
3de0e94e ^






15ee6390 ^
3de0e94e ^





15ee6390 ^
3de0e94e ^
8426aa8e ^
3de0e94e ^
74978738 ^


17292a0c ^
15cf6c4e ^
561ab2d0 ^



74978738 ^

2f65c2ad ^

15cf6c4e ^
2f65c2ad ^





74978738 ^
05931702 ^

0765adfc ^
15cf6c4e ^
cd55bb01 ^
42dee71e ^
15cf6c4e ^
747cbd3b ^

41f8c683 ^
747cbd3b ^
15cf6c4e ^
42dee71e ^

cd55bb01 ^
747cbd3b ^

41f8c683 ^
747cbd3b ^
15cf6c4e ^
74978738 ^
8426aa8e ^
15ee6390 ^



0765adfc ^
15cf6c4e ^
0765adfc ^
















8426aa8e ^
0765adfc ^
8426aa8e ^
0765adfc ^
8426aa8e ^


86d32113 ^
8426aa8e ^

a50564c1 ^


15cf6c4e ^
a50564c1 ^




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
                        
                             
                            

                            
 
                              
                       
                                                                   



                                                            
                     

                                                                          
                                                                       





                                                                 


                     
                                                                   
             
                  
                                               



                              
 
                              

                                 
                                           
                                                    
                                                          

                                                                           

                                                                       

            

                                         
           
                                   



                              
         


                    
                            
                       

                          
     
 
                       
                 

                                       
            
                                     
 








                                              
         
 





                                                       

                                          







                                                               





                                                                          
 
                                    
                                                 






                                                                                          
 





                                          
 
                                
         
       


                     
                             
                                           



                          

     

                                
                                           





                          
                       

                              
 
                                                                
                           
                                                         
                                                                              

                          
                       
                
                                                                

           
          

                      
                   
            
                                                           
     
 



                                                
                              
                                             
















                                                                                        
                       
                                                       
                      
                                               


                                                                  
                                                       

         


                               
                                           




                          
db = require("../redis")
config = require("../config")
bcrypt = require('bcryptjs')
fs = require('fs')
request = require('request')

module.exports = (sessions) ->
  exists: (req, res) ->
    db.hgetall("user:"+req.params.user.toLowerCase(), (err, obj) ->
      if obj? then res.write('true') else res.write('false')
      res.end()
    )
  
  json: (req, res) ->
    res.end() unless req.params.user
    db.llen("#{req.params.user.toLowerCase()}:transactions", (err, len) ->
      db.hgetall("user:#{req.params.user.toLowerCase()}", (err, obj) ->
        delete obj['password']
        obj['index'] = len
        res.writeHead(200, {"Content-Type": "application/json"});
        res.write(JSON.stringify(obj))
        res.end()
      )
    )

  show: (req, res) ->
    db.hgetall("user:"+req.params.user.toLowerCase(), (err, obj) ->
      if obj 
        options = 
          user: req.params.user.toLowerCase(), 
          layout: 'layout',
          navigation: true,
          js: (-> global.js), 
          css: (-> global.css)

        if req.query.verified?
          options.verified = true

        if obj.logo and obj.logo.length > 3
          ext = obj.logo.substr(obj.logo.length - 3)
          path = "public/img/logos/#{obj.username}.#{ext}"
          fs.lstat(path, (err, stats) ->
            if ext in ['jpg', 'png', 'gif'] and (err or not stats.isFile())
              try
                request("#{obj.logo}").pipe(fs.createWriteStream(path))
          )
            
        res.render('users/show', options)
        delete req.session.verified
      else 
        res.render('sessions/new', 
          notice: true,
          layout: 'layout',
          js: (-> global.js), 
          css: (-> global.css)
        )
    )

  new: (req, res) ->
    res.render('users/new', 
      layout: 'layout',
      js: (-> global.js), 
      css: (-> global.css)
    )

  create: (req, res) ->
    errormsg = ""
    userkey = "user:"+req.body.username
    db.hgetall(userkey, (err, obj) ->
      if obj
        errormsg += "Username exists"

      if req.body.confirm != req.body.password
        errormsg += "Passwords must match"

      if errormsg
        return res.render('users/new',
          layout: 'layout',
          js: (-> global.js), 
          css: (-> global.css),
          error: errormsg
        )

      bcrypt.hash(req.body.password, 12, (err, hash) ->
         db.sadd("users",userkey)
         db.hmset(userkey,
           username: req.body.username,
           password: hash,
           email: req.body.email,
           commission: req.body.commission
           unit: req.body.unit,
           pubkey: req.body.pubkey,
           privkey: req.body.privkey
          , ->
            req.session.redirect = "/#{req.body.username}/edit"
            sessions.create(req, res)
         )
      )

      require('crypto').randomBytes(48, (ex, buf) ->
        token = buf.toString('base64').replace(/\//g,'').replace(/\+/g,'')
        db.set("token:#{token}", req.body.username)
        host = req.hostname
        host += ':3000' if host is 'localhost'
        url = "#{req.protocol}://#{host}/verify/#{token}"

        res.render('users/welcome', 
          user: req.body.username.toLowerCase(), 
          layout: 'mail',
          url: url,
          privkey: req.body.privkey,
          js: (-> global.js), 
          css: (-> global.css),
          (err, html) ->
            sendgrid = require('sendgrid')(config.sendgrid_user, config.sendgrid_password)

            email = new sendgrid.Email(
              to: req.body.email
              from: '[email protected]'
              subject: 'Welcome to CoinOS'
              html: html
            )

            sendgrid.send(email)
        )
      )
    )

  edit: (req, res) ->
    res.render('users/edit', 
      user: req.params.user.toLowerCase(), 
      layout: 'layout',
      navigation: true,
      js: (-> global.js), 
      css: (-> global.css)
    )

  profile: (req, res) ->
    res.render('users/profile', 
      user: req.params.user.toLowerCase(), 
      layout: 'layout',
      navigation: true,
      js: (-> global.js), 
      css: (-> global.css)
    )

  update: (req, res) ->
    if req.body.password is ''
      delete req.body.password

    db.hmset("user:"+req.params.user.toLowerCase(), req.body, ->
      if req.body.password?
        bcrypt.hash(req.body.password, 12, (err, hash) ->
          db.hmset("user:#{req.params.user.toLowerCase()}", password: hash, ->
            if req.xhr
              res.send({})
              res.end()
            else
              res.redirect("/#{req.params.user.toLowerCase()}") 
          )
        )
      else
        if req.xhr
          res.send({})
          res.end()
        else
          res.redirect("/#{req.params.user.toLowerCase()}")
    )

    if process.env.NODE_ENV is 'production' and 
    req.body.privkey? and 
    req.body.privkey != '' and 
    req.body.email != ''
      res.render('users/key', 
        user: req.params.user.toLowerCase(), 
        layout: 'mail',
        key: req.body.privkey,
        js: (-> global.js), 
        css: (-> global.css),
        (err, html) ->
          sendgrid = require('sendgrid')(config.sendgrid_user, config.sendgrid_password)

          email = new sendgrid.Email(
            to: req.body.email
            from: '[email protected]'
            subject: 'CoinOS Wallet Key'
            html: html
          )

          sendgrid.send(email)
      )

  verify: (req, res) ->
    db.get("token:#{req.params.token}", (err, reply) ->
      if err or !reply
        res.write("Invalid Verification Token")
        res.end()
      else
        db.hset("user:#{reply.toString()}", "verified", "true", ->
          res.redirect("/#{reply.toString()}?verified")
        )
    )

  wallet: (req, res) ->
    res.render('users/wallet', 
      user: req.params.user.toLowerCase(), 
      layout: 'layout',
      navigation: true,
      js: (-> global.js), 
      css: (-> global.css)
    )