From 97ba9a2ec0750f8cdccfc9f583637c012f28ca94 Mon Sep 17 00:00:00 2001 From: Gunther Brunner Date: Tue, 30 Jun 2015 20:06:38 +0900 Subject: [PATCH] Use webpack instead of require.js for MOCK authentication. Removing Japanese hardcoded strings (Needs gettext loading code). --- res/auth/ldap/scripts/entry.js | 2 +- res/auth/mock/scripts/app.js | 11 ------ res/auth/mock/scripts/bootstrap.js | 11 ------ .../mock/scripts/controllers/SignInCtrl.js | 37 ------------------- res/auth/mock/scripts/controllers/index.js | 6 --- res/auth/mock/scripts/controllers/module.js | 3 -- res/auth/mock/scripts/entry.js | 18 ++++++++- res/auth/mock/scripts/main.js | 19 ---------- res/auth/mock/scripts/routes.js | 17 --------- res/auth/mock/scripts/signin/index.js | 10 +++++ .../mock/scripts/signin/signin-controller.js | 36 ++++++++++++++++++ .../login.css => scripts/signin/signin.css} | 0 .../partials => scripts/signin}/signin.jade | 18 ++++----- res/auth/mock/views/index.jade | 6 +-- res/auth/mock/views/partials/styles.jade | 6 --- 15 files changed, 75 insertions(+), 125 deletions(-) delete mode 100644 res/auth/mock/scripts/app.js delete mode 100644 res/auth/mock/scripts/bootstrap.js delete mode 100644 res/auth/mock/scripts/controllers/SignInCtrl.js delete mode 100644 res/auth/mock/scripts/controllers/index.js delete mode 100644 res/auth/mock/scripts/controllers/module.js delete mode 100644 res/auth/mock/scripts/main.js delete mode 100644 res/auth/mock/scripts/routes.js create mode 100644 res/auth/mock/scripts/signin/index.js create mode 100644 res/auth/mock/scripts/signin/signin-controller.js rename res/auth/mock/{styles/login.css => scripts/signin/signin.css} (100%) rename res/auth/mock/{views/partials => scripts/signin}/signin.jade (68%) delete mode 100644 res/auth/mock/views/partials/styles.jade diff --git a/res/auth/ldap/scripts/entry.js b/res/auth/ldap/scripts/entry.js index 18a20739..a48ca51c 100644 --- a/res/auth/ldap/scripts/entry.js +++ b/res/auth/ldap/scripts/entry.js @@ -15,7 +15,7 @@ require.ensure([], function (require) { $locationProvider.html5Mode(true) $routeProvider .otherwise({ - redirectTo: '/auth/ldap' + redirectTo: '/auth/ldap/' }) }) diff --git a/res/auth/mock/scripts/app.js b/res/auth/mock/scripts/app.js deleted file mode 100644 index 9e34d041..00000000 --- a/res/auth/mock/scripts/app.js +++ /dev/null @@ -1,11 +0,0 @@ -define([ - 'angular' - , './controllers/index' - ] -, function(ng) { - return ng.module('app', [ - 'ngRoute' - , 'app.controllers' - ]) - } -) diff --git a/res/auth/mock/scripts/bootstrap.js b/res/auth/mock/scripts/bootstrap.js deleted file mode 100644 index 19442318..00000000 --- a/res/auth/mock/scripts/bootstrap.js +++ /dev/null @@ -1,11 +0,0 @@ -define([ - 'require' - , 'angular' - , 'angular-route' - , 'app' - , 'routes' - ] -, function(require, ng) { - ng.bootstrap(document, ['app']) - } -) diff --git a/res/auth/mock/scripts/controllers/SignInCtrl.js b/res/auth/mock/scripts/controllers/SignInCtrl.js deleted file mode 100644 index 57c2eb3b..00000000 --- a/res/auth/mock/scripts/controllers/SignInCtrl.js +++ /dev/null @@ -1,37 +0,0 @@ -define(['./module'], function(mod) { - mod.controller('SignInCtrl', ['$scope', '$http', function($scope, $http) { - $scope.error = null - - $scope.submit = function() { - var data = { - name: $scope.signin.username.$modelValue - , email: $scope.signin.email.$modelValue - } - $scope.invalid = false - $http.post('/auth/api/v1/mock', data) - .success(function(response) { - $scope.error = null - location.replace(response.redirect) - }) - .error(function(response) { - switch (response.error) { - case 'ValidationError': - $scope.error = { - $invalid: true - } - break - case 'InvalidCredentialsError': - $scope.error = { - $incorrect: true - } - break - default: - $scope.error = { - $server: true - } - break - } - }) - } - }]) -}) diff --git a/res/auth/mock/scripts/controllers/index.js b/res/auth/mock/scripts/controllers/index.js deleted file mode 100644 index 8a4b268a..00000000 --- a/res/auth/mock/scripts/controllers/index.js +++ /dev/null @@ -1,6 +0,0 @@ -define([ - './SignInCtrl' - ] -, function() { - } -) diff --git a/res/auth/mock/scripts/controllers/module.js b/res/auth/mock/scripts/controllers/module.js deleted file mode 100644 index dc663078..00000000 --- a/res/auth/mock/scripts/controllers/module.js +++ /dev/null @@ -1,3 +0,0 @@ -define(['angular'], function(ng) { - return ng.module('app.controllers', []) -}) diff --git a/res/auth/mock/scripts/entry.js b/res/auth/mock/scripts/entry.js index 40aa0daf..6eb76670 100644 --- a/res/auth/mock/scripts/entry.js +++ b/res/auth/mock/scripts/entry.js @@ -1,5 +1,21 @@ -require.ensure(['angular', 'angular-route'], function (require) { +require.ensure([], function (require) { + require('nine-bootstrap') + require('angular') require('angular-route') + require('angular-touch') + angular.module('app', [ + 'ngRoute', + 'ngTouch', + require('gettext').name, + require('./signin').name + ]) + .config(function ($routeProvider, $locationProvider) { + $locationProvider.html5Mode(true) + $routeProvider + .otherwise({ + redirectTo: '/auth/mock/' + }) + }) }) diff --git a/res/auth/mock/scripts/main.js b/res/auth/mock/scripts/main.js deleted file mode 100644 index de7d5472..00000000 --- a/res/auth/mock/scripts/main.js +++ /dev/null @@ -1,19 +0,0 @@ -require.config({ - paths: { - 'angular': '../../../bower_components/angular/angular' - , 'angular-route': '../../../bower_components/angular-route/angular-route' - } -, shim: { - 'angular': { - exports: 'angular' - } - , 'angular-route': { - deps: [ - 'angular' - ] - } - } -, deps: [ - './bootstrap' - ] -}) diff --git a/res/auth/mock/scripts/routes.js b/res/auth/mock/scripts/routes.js deleted file mode 100644 index 399ddfe6..00000000 --- a/res/auth/mock/scripts/routes.js +++ /dev/null @@ -1,17 +0,0 @@ -define(['./app'], function(app) { - return app.config([ - '$routeProvider' - , '$locationProvider' - , function($routeProvider, $locationProvider) { - $locationProvider.html5Mode(true) - $routeProvider - .when('/auth/mock/', { - templateUrl: '/static/auth/mock/views/partials/signin.html' - , controller: 'SignInCtrl' - }) - .otherwise({ - redirectTo: '/auth/mock/' - }) - } - ]) -}) diff --git a/res/auth/mock/scripts/signin/index.js b/res/auth/mock/scripts/signin/index.js new file mode 100644 index 00000000..ad708aea --- /dev/null +++ b/res/auth/mock/scripts/signin/index.js @@ -0,0 +1,10 @@ +require('./signin.css') + +module.exports = angular.module('stf.signin', []) + .config(function ($routeProvider) { + $routeProvider + .when('/auth/mock/', { + template: require('./signin.jade') + }) + }) + .controller('SignInCtrl', require('./signin-controller')) diff --git a/res/auth/mock/scripts/signin/signin-controller.js b/res/auth/mock/scripts/signin/signin-controller.js new file mode 100644 index 00000000..0cb6ccb8 --- /dev/null +++ b/res/auth/mock/scripts/signin/signin-controller.js @@ -0,0 +1,36 @@ +module.exports = function SignInCtrl($scope, $http) { + + $scope.error = null + + $scope.submit = function () { + var data = { + username: $scope.signin.username.$modelValue + , email: $scope.signin.email.$modelValue + } + $scope.invalid = false + $http.post('/auth/api/v1/mock', data) + .success(function (response) { + $scope.error = null + location.replace(response.redirect) + }) + .error(function (response) { + switch (response.error) { + case 'ValidationError': + $scope.error = { + $invalid: true + } + break + case 'InvalidCredentialsError': + $scope.error = { + $incorrect: true + } + break + default: + $scope.error = { + $server: true + } + break + } + }) + } +} diff --git a/res/auth/mock/styles/login.css b/res/auth/mock/scripts/signin/signin.css similarity index 100% rename from res/auth/mock/styles/login.css rename to res/auth/mock/scripts/signin/signin.css diff --git a/res/auth/mock/views/partials/signin.jade b/res/auth/mock/scripts/signin/signin.jade similarity index 68% rename from res/auth/mock/views/partials/signin.jade rename to res/auth/mock/scripts/signin/signin.jade index a27497f7..1baa352a 100644 --- a/res/auth/mock/views/partials/signin.jade +++ b/res/auth/mock/scripts/signin/signin.jade @@ -1,13 +1,13 @@ -.login2 +.login2(ng-controller='SignInCtrl') .login-wrapper a(href='./') img(width='160', height='160', src='/static/logo/exports/STF-512.png', title='STF') form(name='signin', novalidate, ng-submit='submit()') .alert.alert-danger(ng-show='error') - span(ng-show='error.$invalid') Check errors below - span(ng-show='error.$incorrect') Incorrect login details - span(ng-show='error.$system') System error + span(ng-show='error.$invalid', translate) Check errors below + span(ng-show='error.$incorrect', translate) Incorrect login details + span(ng-show='error.$server', translate) Server error. Check log output. .form-group .input-group @@ -16,7 +16,7 @@ input.form-control(ng-model='username', name='username', required, type='text', placeholder='Name', autocorrect='off', autocapitalize='off', spellcheck='false', autocomplete='section-login username') .alert.alert-warning(ng-show='signin.username.$dirty && signin.username.$invalid') - span Please enter your name + span(translate) Please enter your name .form-group .input-group @@ -25,9 +25,7 @@ input.form-control(ng-model='email', name='email', required, type='email', placeholder='E-mail', autocorrect='off', autocapitalize='off', spellcheck='false', autocomplete='section-login email') .alert.alert-warning(ng-show='signin.email.$dirty && signin.email.$invalid') - span(ng-show='signin.email.$error.email') Please enter a valid email - span(ng-show='signin.email.$error.required') Please enter your email + span(ng-show='signin.email.$error.email', translate) Please enter a valid email + span(ng-show='signin.email.$error.required', translate) Please enter your email - - - input.btn.btn-lg.btn-primary.btn-block(type='submit', value='Log in') + input.btn.btn-lg.btn-primary.btn-block(type='submit', value='Log In') diff --git a/res/auth/mock/views/index.jade b/res/auth/mock/views/index.jade index 27a5565e..dc10113f 100644 --- a/res/auth/mock/views/index.jade +++ b/res/auth/mock/views/index.jade @@ -1,11 +1,11 @@ doctype html -html +html(ng-app='app') head title STF base(href='/') meta(charset='utf-8') meta(name='viewport', content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui') - include partials/styles body(ng-cloak) div(ng-view) - script(src='static/bower_components/requirejs/require.js', data-main='static/auth/mock/scripts/main.js') + script(src='static/app/build/entry/commons.entry.js') + script(src='static/app/build/entry/authmock.entry.js') diff --git a/res/auth/mock/views/partials/styles.jade b/res/auth/mock/views/partials/styles.jade deleted file mode 100644 index 38a52433..00000000 --- a/res/auth/mock/views/partials/styles.jade +++ /dev/null @@ -1,6 +0,0 @@ -link(href='http://fonts.googleapis.com/css?family=Lato:100,300,400,700', media='all', rel='stylesheet', type='text/css') -link(rel='stylesheet', href='/static/bower_components/se7en-bootstrap-3/build/stylesheets/bootstrap.min.css') -link(rel='stylesheet', href='/static/bower_components/se7en-bootstrap-3/build/stylesheets/se7en-font.css') -link(rel='stylesheet', href='/static/bower_components/se7en-bootstrap-3/build/stylesheets/style.css') -link(rel='stylesheet', href='/static/bower_components/se7en-bootstrap-3/build/stylesheets/font-awesome.min.css') -link(rel='stylesheet', href='/static/auth/mock/styles/login.css')