1
0
mirror of https://github.com/Foltik/Shimapan synced 2024-11-28 05:26:44 -05:00

Add login page

This commit is contained in:
Jack 2017-10-11 13:11:57 -04:00
parent e6a09bbe40
commit 616b12d55a
Signed by: foltik
GPG Key ID: 303F88F996E95541
10 changed files with 66 additions and 4 deletions

View File

@ -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') {

9
app/routes/login.js Normal file
View File

@ -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;

View File

@ -1 +1 @@
angular.module('shimapan', ['ngFileUpload', 'ngclipboard', 'UploadComp', 'RegisterComp']);
angular.module('shimapan', ['ngFileUpload', 'ngclipboard', 'UploadComp', 'RegisterComp', 'LoginComp']);

View File

@ -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
});

View File

@ -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
});

View File

@ -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)

View File

@ -16,6 +16,7 @@
<script src="/js/components/UploadComp.js"></script>
<script src="/js/components/RegisterComp.js"></script>
<script src="/js/components/LoginComp.js"></script>
<script src="/js/services/AuthSvc.js"></script>
<script src="/js/app.js"></script>
</head>

View File

@ -0,0 +1,11 @@
<form ng-submit="login()">
<div class="form-group">
<label for="username">Username</label>
<input id="username" class="form-control" type="text" ng-model="username"/>
</div>
<div class="form-group">
<label for="password">Password</label>
<input id="password" class="form-control" type="password" ng-model="password"/>
</div>
<button type="submit" class="btn">Login</button>
</form>

24
public/views/login.html Normal file
View File

@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<base href="/login"/>
<title>Login</title>
<script src="/libs/angular/angular.min.js"></script>
<script src="/libs/ng-file-upload/ng-file-upload-all.min.js"></script>
<script src="https://cdn.rawgit.com/zenorocha/clipboard.js/master/dist/clipboard.min.js"></script>
<script src="/libs/ngclipboard/src/ngclipboard.js"></script>
<script src="/js/components/UploadComp.js"></script>
<script src="/js/components/RegisterComp.js"></script>
<script src="/js/components/LoginComp.js"></script>
<script src="/js/services/AuthSvc.js"></script>
<script src="/js/app.js"></script>
</head>
<body ng-app="shimapan">
<div id="container">
<login-component></login-component>
</div>
</body>
</html>

View File

@ -12,6 +12,7 @@
<script src="/js/components/UploadComp.js"></script>
<script src="/js/components/RegisterComp.js"></script>
<script src="/js/components/LoginComp.js"></script>
<script src="/js/services/AuthSvc.js"></script>
<script src="/js/app.js"></script>
</head>