From 616b12d55a48df4f6ab81dd9577489de0b4339e4 Mon Sep 17 00:00:00 2001 From: Jack Date: Wed, 11 Oct 2017 13:11:57 -0400 Subject: [PATCH] Add login page --- app/routes.js | 2 ++ app/routes/login.js | 9 +++++++++ public/js/app.js | 2 +- public/js/components/LoginComp.js | 15 +++++++++++++++ public/js/components/RegisterComp.js | 3 +-- public/js/services/AuthSvc.js | 2 +- public/views/index.html | 1 + public/views/login-form.html | 11 +++++++++++ public/views/login.html | 24 ++++++++++++++++++++++++ public/views/register.html | 1 + 10 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 app/routes/login.js create mode 100644 public/js/components/LoginComp.js create mode 100644 public/views/login-form.html create mode 100644 public/views/login.html diff --git a/app/routes.js b/app/routes.js index 9bc30f2..576305e 100644 --- a/app/routes.js +++ b/app/routes.js @@ -3,6 +3,7 @@ var upload = require('./routes/upload.js'); var view = require('./routes/view.js'); var auth = require('./routes/auth.js'); var register = require('./routes/register.js'); +var login = require('./routes/login.js'); var fs = require('fs'); var path = require('path'); @@ -18,6 +19,7 @@ module.exports = function(app) { app.use('/upload', upload); app.use('/api/auth', auth); app.use('/register', register); + app.use('/login', login); app.use(function(err, req, res, next) { if (err.name === 'UnauthorizedError') { diff --git a/app/routes/login.js b/app/routes/login.js new file mode 100644 index 0000000..221d87b --- /dev/null +++ b/app/routes/login.js @@ -0,0 +1,9 @@ +var express = require('express'); +var router = express.Router(); +var path = require('path'); + +router.get('/', function(req, res, next) { + res.sendFile(path.join(__dirname, '../../public/views', 'login.html')); +}); + +module.exports = router; \ No newline at end of file diff --git a/public/js/app.js b/public/js/app.js index 41ecedd..5ec4a87 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -1 +1 @@ -angular.module('shimapan', ['ngFileUpload', 'ngclipboard', 'UploadComp', 'RegisterComp']); \ No newline at end of file +angular.module('shimapan', ['ngFileUpload', 'ngclipboard', 'UploadComp', 'RegisterComp', 'LoginComp']); \ No newline at end of file diff --git a/public/js/components/LoginComp.js b/public/js/components/LoginComp.js new file mode 100644 index 0000000..262fff9 --- /dev/null +++ b/public/js/components/LoginComp.js @@ -0,0 +1,15 @@ +function LoginController($scope, AuthService) { + $scope.login = function() { + AuthService.login({ + username: $scope.username, + password: $scope.password + }).then(function() { + alert('Logged In'); + }); + } +} + +angular.module('LoginComp', ['AuthSvc']).component('loginComponent', { + templateUrl: '/views/login-form.html', + controller: LoginController +}); \ No newline at end of file diff --git a/public/js/components/RegisterComp.js b/public/js/components/RegisterComp.js index 77e7e05..4eee58b 100644 --- a/public/js/components/RegisterComp.js +++ b/public/js/components/RegisterComp.js @@ -12,6 +12,5 @@ function RegisterController($scope, AuthService) { angular.module('RegisterComp', ['AuthSvc']).component('registerComponent', { templateUrl: '/views/register-form.html', - controller: RegisterController, - controllerAs: 'vm' + controller: RegisterController }); \ No newline at end of file diff --git a/public/js/services/AuthSvc.js b/public/js/services/AuthSvc.js index 135f7f5..7f4ba2e 100644 --- a/public/js/services/AuthSvc.js +++ b/public/js/services/AuthSvc.js @@ -22,7 +22,7 @@ angular.module('AuthSvc', []).service('AuthService', ['$http', '$window', functi return $http({ method: 'POST', url: '/api/auth/login', - headers: {'Content-Type': 'x-www-form-urlencoded'}, + headers: {'Content-Type': 'application/x-www-form-urlencoded'}, transformRequest: function(obj) { var str = []; for (var p in obj) diff --git a/public/views/index.html b/public/views/index.html index fc7dda8..df30560 100644 --- a/public/views/index.html +++ b/public/views/index.html @@ -16,6 +16,7 @@ + diff --git a/public/views/login-form.html b/public/views/login-form.html new file mode 100644 index 0000000..a560126 --- /dev/null +++ b/public/views/login-form.html @@ -0,0 +1,11 @@ +
+
+ + +
+
+ + +
+ +
\ No newline at end of file diff --git a/public/views/login.html b/public/views/login.html new file mode 100644 index 0000000..7ff0de6 --- /dev/null +++ b/public/views/login.html @@ -0,0 +1,24 @@ + + + + + + Login + + + + + + + + + + + + + +
+ +
+ + diff --git a/public/views/register.html b/public/views/register.html index fe8307f..7365df5 100644 --- a/public/views/register.html +++ b/public/views/register.html @@ -12,6 +12,7 @@ +