Login

Login via ExtJS

Author:
davidblewett
Posted:
June 10, 2008
Language:
Python
Version:
.96
Tags:
ajax login auth ext extjs
Score:
1 (after 1 ratings)

This is a simple view I'm using to log people into our app using ExtJS's AJAX form submission.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from django.core.serializers.json import DjangoJSONEncoder
from django.http import HttpResponse
from django.utils import simplejson

def ext_login(request):
    json = {
        'errors': {},
        'text': {},
        'success': False,
    }
    user = authenticate(username=request.POST['username'],
                        password=request.POST['password'])
    if user is not None:
        if user.is_active:
            login(request, user)
            json['success'] = True
            json['text']['welcome'] = 'Welcome, %s!' % (user.get_full_name(),)
        else:
            # Return a 'disabled account' error message
            json['errors']['username'] = 'Account disabled.'
    else:
        # Return an 'invalid login' error message.
            json['errors']['username'] = 'Username and/or password invalid.'
    return HttpResponse(simplejson.dumps(json, cls=DjangoJSONEncoder))


Sample Ext Panel config, uses Ext.ux.PasswordField
(http://extjs.com/forum/showthread.php?t=20417):
Signet.LoginForm = Ext.extend(Ext.FormPanel, {
    labelAlign: 'right'
    ,labelWidth: 75
    ,title: 'Home'
    ,xtype: 'form'
    ,initComponent:function() {
        Ext.apply(this, {
            buttons:[
                new Ext.Button({
                    handler: this.authSubmit
                    ,scope: this
                    ,text: 'login'
                })
            ]
            ,items:[
                new Ext.form.TextField({
                    fieldLabel: 'User Name'
                    ,name: 'username'
                    ,width: 100
                })
                ,new Ext.ux.PasswordField({
                    fieldLabel: 'Password'
                    ,name: 'password'
                    ,showCapsWarning: true
                    ,showStrengthMeter: false
                    ,width: 100
                })
            ]
        });

        Signet.LoginForm.superclass.initComponent.apply(this, arguments);

        if (this.initialConfig.handler && this.initialConfig.scope){
            this.form.on('actioncomplete', this.initialConfig.handler, this.initialConfig.scope);
            this.form.on('actionfailed', this.initialConfig.handler, this.initialConfig.scope);
        }
    }
    ,authSubmit: function(){
        this.form.submit({
            clientValidation: false
            ,method: 'POST'
            ,url:'/csds/ext/login/'
        });
    }
});

More like this

  1. Login message middleware by nipuL 7 years, 1 month ago
  2. Set test cookie unless logged in by nipuL 7 years, 1 month ago
  3. ajax form handler generic view by amitu 6 years, 6 months ago
  4. Ajax auto-filtered Foreign Key Field by anentropic 5 years, 5 months ago
  5. Require login by url by zbyte64 6 years, 8 months ago

Comments

Please login first before commenting.