Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==========================================================================
- // MyApp.LoginView
- // ==========================================================================
- MyApp.LoginChoices = SC.View.extend(SC.StaticLayout, SC.Control,
- /** @scope MyApp.LoginChoices.prototype */ {
- useStaticLayout: YES,
- classNames: 'modal-container',
- wantsAcceleratedLayer: YES,
- childViews: 'firstname loginButton'.w(),
- user: SC.TextFieldView.design({
- classNames: 'textfield user',
- valueBinding: 'MyApp.authController.user'
- }),
- password: SC.TextFieldView.design({
- classNames: 'textfield password',
- hint: 'password',
- isPassword: YES,
- valueBinding: 'MyApp.authController.password'
- }),
- loginButton: SC.ButtonView.design({
- acceptsFirstResponder: true,
- classNames: 'button',
- title: 'Login!',
- isDefault: YES,
- action: 'submitLogin'
- })
- });
- // ==========================================================================
- // MyApp.authStatechart
- // ==========================================================================
- authLogin: Ki.State.design({
- submitLogin: function (evt) {
- valid = MyApp.authController.validateLogin();
- if (valid) {
- authLogin: function () {
- MyApp.authController.set('errorMessage', '');
- var user = MyApp.authController.get('user');
- var password = MyApp.authController.get('password');
- if (user !== null && password !== null) {
- SC.$.ajax({
- type: 'POST',
- async: false,
- url: "/login/",
- data: { username: user, password: password },
- success: function(data){
- console.info('login success:', data);
- if (data.loggedin) {
- MyApp.coreStatechart.sendAction('loginOk');
- }
- if (data.notActive) {
- MyApp.coreStatechart.sendAction('notActive');
- }
- if (data.invalid) {
- MyApp.authController.set('errorMessage', 'Username or password not valid');
- MyApp.coreStatechart.sendAction('invalidLogin');
- }
- },
- error: function(data){
- console.info('Do something there is an error');
- }
- });
- }else{
- console.info('some field is not filled in');
- }
- }
- }
- }
- });
- // ==========================================================================
- // MyApp.authController
- // ==========================================================================
- MyApp.authController = SC.ObjectController.create(
- /** @scope MyApp.authController.prototype */ {
- user: null,
- password: null
- });
Add Comment
Please, Sign In to add comment