OSDN Git Service

signup page authentication
authorhimetani_cafe <fumifumi@yasunaga-lab.bio.kyutech.ac.jp>
Tue, 28 Jul 2015 13:26:36 +0000 (22:26 +0900)
committerhimetani_cafe <fumifumi@yasunaga-lab.bio.kyutech.ac.jp>
Tue, 28 Jul 2015 13:26:36 +0000 (22:26 +0900)
client/app/app.js
client/app/components/login/.login.controller.js.swp [deleted file]
client/app/components/login/login.controller.js
client/app/components/signup/signup.controller.js
client/app/components/signup/signup.html
orm.js [deleted file]
package.json
server/app.js
server/auth/signup/index.js [new file with mode: 0644]
server/jb.js [new file with mode: 0644]
server/routes.js

index d64f304..b86b968 100644 (file)
@@ -8,21 +8,21 @@ angular.module('zephyrApp', ['ui.bootstrap', 'ui.router', 'restangular','ngRoute
     })
     $urlRouterProvider.otherwise('/login')
     $httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'
-
-    $httpProvider.interceptors.push(function($q, $location) { 
-        return { 
-            response: function(response) { // do something on success 
-                return response 
-            }, 
-            responseError: function(response) { 
-                if (response.status === 401) $location.url('/login') 
-                    return $q.reject(response); 
-            } 
-        }; 
-    })
 })
-.run(function($rootScope, $state) {
+.run(function($rootScope, $state, Restangular) {
     $rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {
         $rootScope.previous = fromState.name
     })
+
+    Restangular.setErrorInterceptor(function(response, deferred, responseHandler) {
+        if(response.status === 401) {
+            $state.go('login')
+        }
+        else if(response.status === 409) {
+            // send signal to SignupController
+            $rootScope.$broadcast('conflict')
+        }
+
+        return false
+    })
 })
diff --git a/client/app/components/login/.login.controller.js.swp b/client/app/components/login/.login.controller.js.swp
deleted file mode 100644 (file)
index 30ca7a3..0000000
Binary files a/client/app/components/login/.login.controller.js.swp and /dev/null differ
index 49fec77..b7da56b 100644 (file)
@@ -7,17 +7,16 @@ angular.module('zephyrApp')
     // show or not alert
     if($rootScope.previous === 'signup') 
         $scope.alert = true 
+    $scope.$watch('alert')
 
     // hide alert
     $scope.close = function() {
         $scope.alert = false 
     }
 
-    $scope.$watch('alert')
     $timeout(function() {
         $scope.close()
     }, 5000)
-    // hide alert
 
     $scope.signup = function() {
         $state.go('signup')
@@ -37,4 +36,5 @@ angular.module('zephyrApp')
         })
     }
 
-});
+})
+
index d870e72..54dd719 100644 (file)
@@ -1,26 +1,47 @@
 'use strict';
 
 angular.module('zephyrApp')
-.controller('SignupController', function ($scope, $modal, Restangular, $state, user) {
+.controller('SignupController', function ($scope, $modal, Restangular, $state, user, $timeout) {
     var baseLogin = Restangular.all('/auth/signup')
 
-    $scope.submit = function() {
-        $state.go('login')
-    }
+    $scope.$watch('alert')
 
-    /*
     $scope.submit = function() {
+        // show alert
+        if(!$scope.role) {
+            $scope.alert = true
+            $scope.alertmsg = "At least one select your role"
+            timeout()
+        }
         var params = {
-            username: $scope.username,
-            password: $scope.password
+            email: $scope.email
         }
+        if($scope.superuser)
+            params.password = $scope.password
+        else
+            params.password = "secret"
 
-        console.log(params)
-
-        baseLogin.post(JSON.stringify(params)).then(function(userID) {
-            user.setID(userID)
-            $state.go('board', { userID: userID })
+        baseLogin.post(JSON.stringify(params)).then(function(status) {
+            $state.go('login')
+            console.log(status)
         })
     }
-    */
-});
+
+    // hide alert
+    $scope.close = function() {
+        $scope.alert = false 
+    }
+
+    function timeout() {
+        $timeout(function() {
+            $scope.close()
+        }, 5000)
+    }
+
+    $scope.$on('conflict', function() {
+        $scope.alert = true
+        $scope.alertmsg = "This email has been registered yet"
+        timeout()
+    })
+
+})
index 517ce73..cbe1632 100644 (file)
@@ -1,9 +1,34 @@
 <div class="container">
-
+<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4 pull-right">
+    <alert type="danger" close="close()" ng-show="alert" ng-click="close()">{{alertmsg}}</alert>
+</div>
 <form class="form-signin" ng-submit="submit()" >
     <h2 class="text-center" class="form-signin-heading">Singup</h2>
     <label class="sr-only">email</label>
-    <input type="text" name="username" class="form-control" ng-model="email" placeholder="email" required autofocus>
+    <input type="email"class="form-control" ng-model="email" placeholder="email" required autofocus>
+    <label class="sr-only">password</label>
+    <input type="password" class="form-control" ng-model="password" placeholder="password" ng-show="role.superuser" ng-disabled="!role.superuser" required autofocus>
+    <div class="text-center">
+        <h4>role</h4>
+        <div class="checkbox">
+            <label>
+                <input type="checkbox" 
+                       ng-model="role.superuser">Superuser
+            </label>
+        </div>
+        <div class="checkbox">
+            <label>
+                <input type="checkbox"
+                       ng-model="role.expert">Expert user
+            </label>
+        </div>
+        <div class="checkbox">
+            <label>
+                <input type="checkbox"
+                       ng-model="role.amature">Amature user
+            </label>
+        </div>
+    </div>
     <button class="btn btn-lg btn-primary btn-block" type="submit" ng-submit="register()">Register</button>
 </form>
 
diff --git a/orm.js b/orm.js
deleted file mode 100644 (file)
index c41cb77..0000000
--- a/orm.js
+++ /dev/null
@@ -1,35 +0,0 @@
-var Sequelize = require('sequelize')
-
-var sequelize = new Sequelize('database', 'username', 'password', {
-    host: 'localhost',
-    dialect: 'sqlite',
-
-    pool: {
-        max: 5,
-        min: 0,
-        idle: 10000
-    },
-
-    // SQLite only
-    storage: 'db/auth.db'
-});
-
-var User = sequelize.define('user', {
-      firstName: {
-              type: Sequelize.STRING,
-                  field: 'first_name' // Will result in an attribute that is firstName when user facing but first_name in the database
-                    },
-                      lastName: {
-                              type: Sequelize.STRING
-                                }
-}, {
-      freezeTableName: true // Model tableName will be the same as the model name
-});
-
-User.sync({force: true}).then(function () {
-      // Table created
-        return User.create({
-                firstName: 'John',
-                    lastName: 'Hancock'
-                      });
-});
index 3008900..7a8b79c 100644 (file)
@@ -8,10 +8,12 @@
     "body-parser": "^1.12.3",
     "connect-flash": "^0.1.1",
     "cookie-parser": "^1.3.5",
+    "ejdb": "^1.2.10-34",
     "ejs": "^2.3.1",
     "express": "^4.12.3",
     "express-session": "^1.11.3",
     "lodash": "^3.8.0",
+    "nan": "^1.8.4",
     "passport": "^0.2.2",
     "passport-local": "^1.0.0",
     "sequelize": "^3.4.1",
index cc33e17..c593f8b 100644 (file)
@@ -3,7 +3,8 @@
 var express = require('express'),
     config  = require('./config'),
     app     = express(),
-    server  = require('http').createServer(app)
+    server  = require('http').createServer(app),
+    jb      = require('./jb')
 
 require('./express')(app);
 require('./routes')(app);
diff --git a/server/auth/signup/index.js b/server/auth/signup/index.js
new file mode 100644 (file)
index 0000000..ec7bd6e
--- /dev/null
@@ -0,0 +1,30 @@
+'use strict'
+
+var express = require('express'),
+    router  = express.Router(),
+    jb      = require('../../jb')
+
+
+router.post('/', function(req, res) {
+    var email = req.params.email
+    var password = req.params.password
+    jb.find('user', 
+               { email: req.params.email },
+           function(err, document) {
+                if(document.length === 0) {
+                    var newuser = {
+                        email: email,
+                        password: password,
+                        role : [],
+                        notes: [],
+                        workspaces:[]
+                    }
+                    jb.save('user', newuser)
+                    res.sendStatus(200)
+                } else {
+                    res.sendStatus(409)
+                }
+           })
+})
+
+module.exports = router
diff --git a/server/jb.js b/server/jb.js
new file mode 100644 (file)
index 0000000..7bd718a
--- /dev/null
@@ -0,0 +1,6 @@
+'use strict'
+
+var EJDB = require('ejdb'),
+    jb = EJDB.open("db/user.db")
+
+module.exports = jb 
index b0eceb7..5ad4255 100644 (file)
@@ -3,6 +3,8 @@
 var path = require('path');
 
 module.exports = function(app) {
+
+    // Routing
     app.use('/api/optionControlFile', require('./api/optionControlFile'))
     app.use('/api/commandList', require('./api/commandList'))
     app.use('/api/tagList', require('./api/tagList'))
@@ -12,6 +14,9 @@ module.exports = function(app) {
     app.use('/api/noteCreation', require('./api/noteCreation'))
     app.use('/api/noteInfo', require('./api/noteInfo'))
     app.use('/auth/login', require('./auth/login'))
+    app.use('/auth/signup', require('./auth/signup'))
+
+
     app.route('/*')
     .get(function(req, res) {
         if(app.get('env') === 'development') {