aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/App.vue200
-rw-r--r--src/components/SignIn.vue44
-rw-r--r--src/main.js26
-rw-r--r--src/routes/sessions.coffee20
-rw-r--r--src/routes/users.coffee248
5 files changed, 287 insertions, 251 deletions
diff --git a/src/App.vue b/src/App.vue
new file mode 100644
index 00000000..90059e78
--- /dev/null
+++ b/src/App.vue
@@ -0,0 +1,200 @@
+<template lang="pug">
+ router-view
+</template>
+
+<script>
+import SignIn from './components/SignIn'
+
+export default {
+ name: 'App',
+ components: {
+ SignIn
+ }
+}
+</script>
+
+<style lang="stylus">
+ @media (min-width: 580px)
+ .mobile
+ display none
+
+ @media (max-width: 360px)
+ .tablet
+ display none
+
+ h1
+ margin-top 0
+
+ div
+ &.container-fluid
+ max-width 580px
+ margin-left auto
+ margin-right auto
+ text-align left
+ padding 0
+ padding-bottom 10px
+
+ .navbar-toggle
+ background-color #428bca
+ width 100%
+ position absolute
+ top 0px
+ height 30px
+ margin 0
+ float none
+ z-index 1
+ margin-bottom -30px
+ .glyphicon
+ margin-top -5px
+ padding-left 10px
+
+ .navbar
+ margin 0
+ min-height 40px
+
+ .navbar-collapse
+ &.in
+ overflow-y visible
+
+ #connection
+ display none
+
+ .numpad .btn,
+ .tippad .btn
+ margin-bottom 5px
+ width 6em
+
+ .numpad h2,
+ .tippad h2
+ margin-bottom 2px
+ margin-top 1px
+
+ .numpad
+ width 26em
+
+ .rates
+ margin-top -15px
+ h2
+ .label
+ font-size 14px
+ position relative
+ top -5px
+
+ #slide
+ height 1.8em
+ width 100%
+ margin-bottom 2px
+
+ @media (max-width: 360px)
+ .tippad
+ .btn
+ width 4.3em
+ .numpad
+ .btn
+ width 5.7em
+ .rates
+ width 100%
+ text-align left
+ #address
+ font-size 16px
+
+ .numpad,
+ .tippad,
+ .rates,
+
+ #payment
+ h2
+ margin-bottom 2px
+
+ .no-transition
+ -webkit-transition height 0.01s
+ -moz-transition height 0.01s
+ -ms-transition height 0.01s
+ -o-transition height 0.01s
+ transition height 0.01s
+
+ #nav
+ .nav
+ margin-top 30px
+ li
+ a
+ padding 10px 0 10px 10px
+
+ .form-group
+ label
+ font-weight normal
+ font-size 14px
+ display block
+ .form-control
+ height auto
+ padding 3px
+ display inline-block
+ .input-group-addon
+ color #000
+ .input-group-btn
+ padding-top 24px
+ .form-control-feedback
+ margin-top 24px
+
+ .form-group p,
+ .form-group span,
+ .form-group .form-control
+ font-size 18px
+
+ .form-group span,
+ .form-group label
+ color #999
+
+ div#calculator
+ #amount
+ width 5em
+ #received
+ font-size 16px
+ width 100%
+ strong#total
+ font-size 30px
+ #address
+ padding-top 10px
+ a
+ color #fff
+ text-decoration none
+ #title
+ display none
+ a
+ color #000
+ text-decoration none
+ #logo
+ display none
+ padding 10px 0
+ margin-bottom 10px
+ max-height 225px
+ width 100%
+ #error
+ margin-top 10px
+ #qr
+ padding-bottom 10px
+ margin-left 20px
+ .numpad
+ .btn-primary
+ background #abc
+
+ td
+ &.total
+ font-weight bold
+ text-align right
+
+ #main-logo
+ background-image url('/static/img/coinos_logo.png')
+ width 300px
+ height 80px
+ margin-top 10px
+ margin-bottom 10px
+
+ .svg
+ #main-logo
+ background-image url('/static/img/coinos_logo.svg') !important
+ background-size 300px 80px
+
+ @page
+ margin 0
+</style>
diff --git a/src/components/SignIn.vue b/src/components/SignIn.vue
new file mode 100644
index 00000000..37a49d5f
--- /dev/null
+++ b/src/components/SignIn.vue
@@ -0,0 +1,44 @@
+<template lang="pug">
+div
+ #main-logo
+ p.alert.alert-danger Invalid username or password, please try again.
+ form.form-signin(action='login', method='post')
+ input.form-control(name='username', type='text', placeholder='Username', value='user', required='', autofocus='')
+ br
+ |
+ input.form-control(name='password', type='password', placeholder='Password', required='')
+ br
+ |
+ button.btn.btn-lg.btn-primary.btn-block(type='submit') Sign in
+ p
+ button#register.btn.btn-lg.btn-secondary.btn-block Register
+ p
+ a(href='http://bitcoincoop.org/coinos') What is this?
+</template>
+
+<script>
+export default {
+ name: 'home'
+}
+</script>
+
+<style lang="stylus">
+ #main-logo
+ margin-bottom 15px
+
+ .form-signin
+ margin-bottom 10px
+ .form-control
+ height auto
+ -webkit-box-sizing border-box
+ -moz-box-sizing border-box
+ box-sizing border-box
+ padding 10px
+ font-size 16px
+
+ .notice
+ border 1px solid gray
+ background #eee
+ padding 10px
+ margin-bottom 15px
+</style>
diff --git a/src/main.js b/src/main.js
new file mode 100644
index 00000000..e4ae5c1a
--- /dev/null
+++ b/src/main.js
@@ -0,0 +1,26 @@
+// The Vue build version to load with the `import` command
+// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
+import Vue from 'vue'
+import VueRouter from 'vue-router'
+import App from './App'
+import SignIn from './components/SignIn'
+
+const routes = [
+ { path: '/', component: SignIn },
+ { path: '/signin', component: SignIn }
+]
+
+const router = new VueRouter({
+ routes // short for routes: routes
+})
+
+Vue.use(VueRouter)
+
+/* eslint-disable no-new */
+new Vue({
+ el: '#app',
+ template: '<app/>',
+ components: { App },
+ router: router
+})
+
diff --git a/src/routes/sessions.coffee b/src/routes/sessions.coffee
index 6a441c75..70c18b4e 100644
--- a/src/routes/sessions.coffee
+++ b/src/routes/sessions.coffee
@@ -1,9 +1,8 @@
module.exports = (passport) ->
new: (req, res) ->
res.render('sessions/new',
- layout: 'layout',
js: (-> global.js),
- css: (-> global.css)
+ css: (-> global.css)
)
create: (req, res, next) ->
@@ -11,23 +10,12 @@ module.exports = (passport) ->
if (err)
return next(err)
if (!user)
- return res.render('sessions/new',
- layout: 'layout',
- js: (-> global.js),
- css: (-> global.css),
- badpw: true
- )
- req.session.user = user
+ return res.redirect('/login')
req.login(user, (err) ->
if (err)
return next(err)
-
- re = new RegExp(user.username, 'g')
- if req.session.redirect? and re.test(req.session.redirect)
- url = req.session.redirect
-
- url ?= "/#{user.username}"
- delete req.session.redirect
+ url = req.headers['referer']
+ url = "/#{user.username}" unless /edit/.test(url)
return res.redirect(url)
)
)(req, res, next)
diff --git a/src/routes/users.coffee b/src/routes/users.coffee
index 7b2f1f3a..1611f691 100644
--- a/src/routes/users.coffee
+++ b/src/routes/users.coffee
@@ -1,253 +1,31 @@
-Promise = require('bluebird')
-db = require("../redis")
-config = require("../config")
-bcrypt = require('bcryptjs')
-fs = require('fs')
-request = require('request')
+db = require("redis").createClient()
+bcrypt = require('bcrypt')
module.exports = (sessions) ->
exists: (req, res) ->
- db.hgetall("user:"+req.params.user.toLowerCase(), (err, obj) ->
+ db.hgetall(req.params.user, (err, obj) ->
if obj? then res.write('true') else res.write('false')
res.end()
)
- index: (req, res) ->
- result = 'users': []
- db.keysAsync("user:*").then((users) ->
- Promise.all(users.map((key) ->
- db.hgetallAsync(key).then((user) ->
- delete user['password']
- result.users.push(user)
- )
- ))
- ).then(->
- res.writeHead(200, {"Content-Type": "application/json"});
- res.write(JSON.stringify(result))
- 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)
+ css: (-> global.css),
)
create: (req, res) ->
- errormsg = ""
- userkey = "user:"+req.body.username
- db.hgetall(userkey, (err, obj) ->
+ db.hgetall(req.body.username, (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) ->
-
- helper = require('sendgrid').mail
- from_email = new helper.Email('[email protected]')
- to_email = new helper.Email(req.body.email)
- subject = 'Welcome to CoinOS'
- content = new helper.Content('text/html', html)
- mail = new helper.Mail(from_email, subject, to_email, content)
-
- sg = require('sendgrid')(config.sendgrid_token)
- request = sg.emptyRequest(
- method: 'POST'
- path: '/v3/mail/send'
- body: mail.toJSON()
- )
-
- sg.API(request, (error, response) ->
- console.log(response.statusCode)
- console.log(response.body)
- console.log(response.headers)
- )
- )
- )
- )
-
- 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, ->
- req.session.user = req.body
- delete req.session.user.password
-
- if req.body.password?
- bcrypt.hash(req.body.password, 12, (err, password) ->
- db.hmset("user:#{req.params.user.toLowerCase()}",
- email: email
- password: password
- phone: phone
- , ->
- if req.xhr
- res.send({})
- res.end()
- else
- res.redirect("/#{req.params.user.toLowerCase()}")
- )
- )
+ res.redirect(req.body.username)
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) ->
- helper = require('sendgrid').mail
- from_email = new helper.Email('[email protected]')
- to_email = new helper.Email(req.body.email)
- subject = 'CoinOS Wallet Key'
- content = new helper.Content('text/html', html)
- mail = new helper.Mail(from_email, subject, to_email, content)
-
- sg = require('sendgrid')(config.sendgrid_token)
- request = sg.emptyRequest(
- method: 'POST'
- path: '/v3/mail/send'
- body: mail.toJSON()
- )
-
- sg.API(request, (error, response) ->
- console.log(response.statusCode)
- console.log(response.body)
- console.log(response.headers)
+ bcrypt.hash(req.body.password, 12, (err, hash) ->
+ db.hmset(
+ req.body.username,
+ {username: req.body.username, password: hash},
+ ->
+ req.headers['referer'] = "/#{req.body.username}/edit"
+ sessions.create(req, res)
)
- )
-
- 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)
- )