1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-15 10:46:32 +00:00

add PersonalSettingModal

This commit is contained in:
Rokt33r
2015-07-24 15:13:04 +09:00
parent 2f754bbb87
commit 2e4aaf7345
14 changed files with 460 additions and 67 deletions

View File

@@ -4,16 +4,19 @@ var request = require('superagent')
var AuthActions = require('../Actions/AuthActions')
var apiUrl = 'http://localhost:8000/'
var AuthStore = Reflux.createStore({
init: function () {
this.listenTo(AuthActions.login, this.login)
this.listenTo(AuthActions.register, this.register)
this.listenTo(AuthActions.logout, this.logout)
this.listenTo(AuthActions.updateProfile, this.updateProfile)
},
// Reflux Store
login: function (input) {
request
.post('http://localhost:8000/auth/login')
.post(apiUrl + 'auth/login')
.send(input)
.set('Accept', 'application/json')
.end(function (err, res) {
@@ -27,12 +30,15 @@ var AuthStore = Reflux.createStore({
localStorage.setItem('token', res.body.token)
localStorage.setItem('user', JSON.stringify(res.body.user))
this.trigger(user)
this.trigger({
status: 'loggedIn',
data: user
})
}.bind(this))
},
register: function (input) {
request
.post('http://localhost:8000/auth/signup')
.post(apiUrl + 'auth/signup')
.send(input)
.set('Accept', 'application/json')
.end(function (err, res) {
@@ -46,14 +52,42 @@ var AuthStore = Reflux.createStore({
localStorage.setItem('token', res.body.token)
localStorage.setItem('user', JSON.stringify(res.body.user))
this.trigger(user)
this.trigger({
status: 'registered',
data: user
})
}.bind(this))
},
logout: function () {
localStorage.removeItem('token')
localStorage.removeItem('user')
this.trigger()
this.trigger({
status: 'loggedOut'
})
},
updateProfile: function (input) {
request
.put(apiUrl + 'auth/user')
.set({
Authorization: 'Bearer ' + localStorage.getItem('token')
})
.send(input)
.end(function (err, res) {
if (err) {
console.error(err)
this.trigger(null)
return
}
var user = res.body
localStorage.setItem('user', JSON.stringify(user))
this.trigger({
status: 'userProfileUpdated',
data: user
})
}.bind(this))
},
// Methods
check: function () {