From c588dd87c6b8d3c3bf2464cda089e64bc17460da Mon Sep 17 00:00:00 2001 From: Gunther Brunner Date: Tue, 30 Jun 2015 19:44:04 +0900 Subject: [PATCH] Use webpack instead of require.js for LDAP authentication. Removing Japanese hardcoded strings (Needs gettext loading code). --- res/auth/ldap/scripts/app.js | 11 ------ res/auth/ldap/scripts/bootstrap.js | 11 ------ .../ldap/scripts/controllers/SignInCtrl.js | 37 ------------------- res/auth/ldap/scripts/controllers/index.js | 6 --- res/auth/ldap/scripts/controllers/module.js | 3 -- res/auth/ldap/scripts/entry.js | 19 +++++++++- res/auth/ldap/scripts/main.js | 19 ---------- res/auth/ldap/scripts/routes.js | 17 --------- res/auth/ldap/scripts/signin/index.js | 10 +++++ .../ldap/scripts/signin/signin-controller.js | 36 ++++++++++++++++++ .../login.css => scripts/signin/signin.css} | 0 .../partials => scripts/signin}/signin.jade | 24 +++++------- res/auth/ldap/views/index.jade | 6 +-- res/auth/ldap/views/partials/styles.jade | 6 --- webpack.config.js | 2 +- 15 files changed, 77 insertions(+), 130 deletions(-) delete mode 100644 res/auth/ldap/scripts/app.js delete mode 100644 res/auth/ldap/scripts/bootstrap.js delete mode 100644 res/auth/ldap/scripts/controllers/SignInCtrl.js delete mode 100644 res/auth/ldap/scripts/controllers/index.js delete mode 100644 res/auth/ldap/scripts/controllers/module.js delete mode 100644 res/auth/ldap/scripts/main.js delete mode 100644 res/auth/ldap/scripts/routes.js create mode 100644 res/auth/ldap/scripts/signin/index.js create mode 100644 res/auth/ldap/scripts/signin/signin-controller.js rename res/auth/ldap/{styles/login.css => scripts/signin/signin.css} (100%) rename res/auth/ldap/{views/partials => scripts/signin}/signin.jade (52%) delete mode 100644 res/auth/ldap/views/partials/styles.jade diff --git a/res/auth/ldap/scripts/app.js b/res/auth/ldap/scripts/app.js deleted file mode 100644 index 9e34d041..00000000 --- a/res/auth/ldap/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/ldap/scripts/bootstrap.js b/res/auth/ldap/scripts/bootstrap.js deleted file mode 100644 index 19442318..00000000 --- a/res/auth/ldap/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/ldap/scripts/controllers/SignInCtrl.js b/res/auth/ldap/scripts/controllers/SignInCtrl.js deleted file mode 100644 index bc096850..00000000 --- a/res/auth/ldap/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 = { - username: $scope.signin.username.$modelValue - , password: $scope.signin.password.$modelValue - } - $scope.invalid = false - $http.post('/auth/api/v1/ldap', 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/ldap/scripts/controllers/index.js b/res/auth/ldap/scripts/controllers/index.js deleted file mode 100644 index 8a4b268a..00000000 --- a/res/auth/ldap/scripts/controllers/index.js +++ /dev/null @@ -1,6 +0,0 @@ -define([ - './SignInCtrl' - ] -, function() { - } -) diff --git a/res/auth/ldap/scripts/controllers/module.js b/res/auth/ldap/scripts/controllers/module.js deleted file mode 100644 index dc663078..00000000 --- a/res/auth/ldap/scripts/controllers/module.js +++ /dev/null @@ -1,3 +0,0 @@ -define(['angular'], function(ng) { - return ng.module('app.controllers', []) -}) diff --git a/res/auth/ldap/scripts/entry.js b/res/auth/ldap/scripts/entry.js index 40aa0daf..18a20739 100644 --- a/res/auth/ldap/scripts/entry.js +++ b/res/auth/ldap/scripts/entry.js @@ -1,5 +1,22 @@ -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/ldap' + }) + }) }) diff --git a/res/auth/ldap/scripts/main.js b/res/auth/ldap/scripts/main.js deleted file mode 100644 index de7d5472..00000000 --- a/res/auth/ldap/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/ldap/scripts/routes.js b/res/auth/ldap/scripts/routes.js deleted file mode 100644 index 0b74650a..00000000 --- a/res/auth/ldap/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/ldap/', { - templateUrl: '/static/auth/ldap/views/partials/signin.html' - , controller: 'SignInCtrl' - }) - .otherwise({ - redirectTo: '/auth/ldap/' - }) - } - ]) -}) diff --git a/res/auth/ldap/scripts/signin/index.js b/res/auth/ldap/scripts/signin/index.js new file mode 100644 index 00000000..83ca07a4 --- /dev/null +++ b/res/auth/ldap/scripts/signin/index.js @@ -0,0 +1,10 @@ +require('./signin.css') + +module.exports = angular.module('stf.signin', []) + .config(function ($routeProvider) { + $routeProvider + .when('/auth/ldap/', { + template: require('./signin.jade') + }) + }) + .controller('SignInCtrl', require('./signin-controller')) diff --git a/res/auth/ldap/scripts/signin/signin-controller.js b/res/auth/ldap/scripts/signin/signin-controller.js new file mode 100644 index 00000000..e9d08c87 --- /dev/null +++ b/res/auth/ldap/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 + , password: $scope.signin.password.$modelValue + } + $scope.invalid = false + $http.post('/auth/api/v1/ldap', 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/ldap/styles/login.css b/res/auth/ldap/scripts/signin/signin.css similarity index 100% rename from res/auth/ldap/styles/login.css rename to res/auth/ldap/scripts/signin/signin.css diff --git a/res/auth/ldap/views/partials/signin.jade b/res/auth/ldap/scripts/signin/signin.jade similarity index 52% rename from res/auth/ldap/views/partials/signin.jade rename to res/auth/ldap/scripts/signin/signin.jade index c169a447..b73d4d44 100644 --- a/res/auth/ldap/views/partials/signin.jade +++ b/res/auth/ldap/scripts/signin/signin.jade @@ -1,36 +1,30 @@ -.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') 下記エラーを確認してください - //span(ng-show='error.$invalid') Check errors below - span(ng-show='error.$incorrect') ユーザー名とパスワードが間違っています - //span(ng-show='error.$incorrect') Incorrect login details - span(ng-show='error.$system') システム・エラー - //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 span.input-group-addon i.fa.fa-user - input.form-control(ng-model='username', name='username', required, type='text', placeholder='LDAPユーザ名', + input.form-control(ng-model='username', name='username', required, type='text', placeholder='LDAP Username', autocorrect='off', autocapitalize='off', spellcheck='false', autocomplete='section-login username') .alert.alert-warning(ng-show='signin.username.$dirty && signin.username.$invalid') - span(ng-show='signin.username.$error.required') LDAPユーザ名を入力してください - //span(ng-show='signin.username.$error.required') Please enter your LDAP username + span(ng-show='signin.username.$error.required', translate) Please enter your LDAP username .form-group .input-group span.input-group-addon i.fa.fa-lock - input.form-control(ng-model='password', name='password', required, type='password', placeholder='パスワード', + input.form-control(ng-model='password', name='password', required, type='password', placeholder='Password', autocorrect='off', autocapitalize='off', spellcheck='false', autocomplete='section-login current-password') .alert.alert-warning(ng-show='signin.password.$dirty && signin.password.$invalid') - span パスワードを入力してください - //span Please enter your password + span(translate) Please enter your password - input.btn.btn-lg.btn-primary.btn-block(type='submit', value='ログイン') - //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/ldap/views/index.jade b/res/auth/ldap/views/index.jade index 21c34d89..79e47bf3 100644 --- a/res/auth/ldap/views/index.jade +++ b/res/auth/ldap/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/ldap/scripts/main.js') + script(src='static/app/build/entry/commons.entry.js') + script(src='static/app/build/entry/authldap.entry.js') diff --git a/res/auth/ldap/views/partials/styles.jade b/res/auth/ldap/views/partials/styles.jade deleted file mode 100644 index 7eddb29b..00000000 --- a/res/auth/ldap/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/ldap/styles/login.css') diff --git a/webpack.config.js b/webpack.config.js index 98c85ff2..e94f3e22 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -27,7 +27,7 @@ module.exports = { }, resolve: { root: [ - pathutil.resource('app/components'), + pathutil.resource('app/components') ], modulesDirectories: [ 'web_modules',