svn: /web/doc-editor/trunk/js/ login.js

[email protected] (Yannick Torres)
Newsgroups php.doc.web
Message-ID <[email protected]>
yannick                                  Thu, 21 Jul 2011 10:07:18 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=313513

Log:
add button to connect with external credential

Changed paths:
    U   web/doc-editor/trunk/js/login.js
svn-diffs-313513.txt (text/x-diff, 21.2 KB)
Modified: web/doc-editor/trunk/js/login.js
===================================================================
--- web/doc-editor/trunk/js/login.js	2011-07-21 10:06:44 UTC (rev 313512)
+++ web/doc-editor/trunk/js/login.js	2011-07-21 10:07:18 UTC (rev 313513)
@@ -8,6 +8,8 @@
         storeLang    : '',
         storeProject : '',
         email : Ext.util.Cookies.get("email"),
+        authService: 'VCS',
+        authServiceID: '',

         init : function()
         {
@@ -50,8 +52,6 @@
                         {name : 'name'},
                         {name : 'request_account_uri'}
                     ]
-
-
                 })
             });

@@ -61,6 +61,23 @@

         },

+        externalCredentials : function(service, name, id, email) {
+
+            this.authService = service;
+            this.authServiceID = id;
+
+            // Name is always given
+            Ext.getCmp('login-form-vcsLogin').setValue(name);
+            Ext.getCmp('login-form-vcsLogin').disable();
+            Ext.getCmp('login-form-vcsPasswd').disable();
+
+            if( email ) {
+                Ext.getCmp('login-form-email').setValue(email);
+            }
+
+            Ext.getCmp('login-btn').setText('Anonymous login');
+        },
+
         drawForm : function()
         {
             var win;
@@ -76,6 +93,12 @@
                     plain       : true,
                     title       : 'Control Access',
                     iconCls     : 'iconKey',
+                    listeners: {
+                        show: function(w) {
+                            win.drawers.e.show();
+                            win.drawers.e.setHeight(240);
+                        }
+                    },
                     plugins     : [
                         new Ext.ux.plugins.WindowDrawer({
                             html      : 'To request a VCS account please read :<div style="text-align: center; margin-top: 20px;"><span id="request-account"></span></div>',
@@ -84,6 +107,211 @@
                             animate   : true,
                             resizable : false,
                             height    : 80
+                        }),
+                        new Ext.ux.plugins.WindowDrawer({
+                            title:'&nbsp;&nbsp;Sign in with...',
+                            side      : 'e',
+                            animate   : true,
+                            resizable : false,
+                            width     : 270,
+                            height    : 250,
+                            items: [{
+                                xtype:'panel',
+                                layout:'accordion',
+                                border: false,
+                                autoHeight: true,
+                                defaults: {
+                                    bodyStyle: 'padding:15px;'
+                                },
+                                layoutConfig: {
+                                    animate: true,
+                                    border: false,
+                                    height: 100
+                                },
+                                items: [{
+                                    title: 'Facebook',
+                                    layout:'fit',
+                                    collapsed : true,
+                                    iconCls:'iconFacebook',
+                                    html: '<div id="facebook-box">'+
+                                            '<div id="fb-root"></div>'+
+                                            '<div id="fb-info">'+
+                                                '<img style="margin-right:5px" align="left" id="fb-image">'+
+                                                ' <span id="fb-name"></span><br>'+
+                                                ' <span id="fb-use-credentials">Use this credentials</span><br><br>'+
+                                                ' <a href="#" onclick="FB.logout(); return false;">Sign out</a><br>'+
+                                            '</div>'+
+                                            '<div id="fb-login">'+
+                                                '<fb:login-button perms="email">Login with Facebook</fb:login-button>'+
+                                            '</div>'+
+                                          '</div>',
+                                    listeners: {
+                                        resize: function(c) {
+                                            c.setHeight(100);
+                                        },
+                                        afterrender: function(c) {
+                                            FB.init({
+                                                appId:'128417830579090', cookie:true,
+                                                status:true, xfbml:true
+                                            });
+
+                                            Ext.get('fb-info').setVisibilityMode(Ext.Element.DISPLAY);
+                                            Ext.get('fb-login').setVisibilityMode(Ext.Element.DISPLAY);
+
+                                            function displayInfo(user) {
+
+                                                //Ensure this bloc is displayed
+                                                Ext.get('fb-info').setVisible(true);
+
+                                                var image = Ext.get('fb-image').dom,
+                                                    name = Ext.get('fb-name').dom;
+
+                                                image.src = 'http://graph.facebook.com/' + user.id + '/picture';
+                                                name.innerHTML = user.name;
+
+                                                Ext.get('fb-use-credentials').on('click', function() {
+                                                    PhDOE_loginPage.externalCredentials('facebook', user.username, user.id, user.email);
+                                                });
+
+
+                                                // We hide the connect button
+                                                Ext.get('fb-login').setVisible(false);
+
+                                            }
+
+                                            FB.api('/me', function(user) {
+
+                                                if(! user.error) {
+                                                    displayInfo(user);
+                                                } else {
+
+                                                    Ext.get('fb-info').setVisible(false);
+                                                }
+                                            });
+
+                                            FB.Event.subscribe('auth.login', function(response) {
+
+                                                FB.api('/me', function(user) {
+                                                    if( !user.error ) {
+                                                        displayInfo(user);
+                                                    }
+                                                });
+                                            });
+
+                                            FB.Event.subscribe('auth.logout', function(response) {
+
+                                                // We display the connect button
+                                                Ext.get('fb-login').setVisible(true);
+
+                                                // Hide info
+                                                Ext.get('fb-info').setVisible(false);
+
+
+                                            });
+
+                                        }
+                                    }
+                                },{
+                                    title: 'Google Friend Connect',
+                                    iconCls:'iconGoogle',
+                                    collapsed : true,
+                                    html: '<div id="google-box"></div>',
+                                    listeners: {
+                                        resize: function(c) {
+                                            c.setHeight(100);
+                                        },
+                                        afterrender: function(cmp) {
+
+                                            google.friendconnect.container.loadOpenSocialApi({
+                                                site: '05056619882644935463',
+                                                onload: function() {
+                                                    GGinitAllData();
+                                                    cmp.doLayout();
+                                                }
+                                            });
+
+                                            function GGinitAllData() {
+                                                var params = {};
+                                                params[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] =
+                                                    [opensocial.Person.Field.ID,opensocial.Person.Field.NAME,opensocial.Person.Field.THUMBNAIL_URL];
+                                                var req = opensocial.newDataRequest();
+                                                req.add(req.newFetchPersonRequest('VIEWER', params), 'viewer');
+                                                req.send(GGsetupData);
+                                            };
+
+                                            function GGsetupData(data) {
+
+                                                viewer = data.get('viewer').getData();
+
+                                                if (viewer) {
+                                                    document.getElementById('google-box').innerHTML =
+                                                    '<img style="margin-right:5px" align="left" src="' + viewer.getField("thumbnailUrl")  + '">' +
+                                                    viewer.getField("displayName") + '<br>'+
+                                                    '<a href="#" onclick="PhDOE_loginPage.externalCredentials(\'google\', \''+viewer.getField("displayName")+'\', \''+viewer.getField("id")+'\' ); return false;">Use this credentials</a><br><br>'+
+                                                    '<a href="#" onclick="google.friendconnect.requestSignOut(); return false;">Sign out</a><br>';
+                                                } else {
+                                                    google.friendconnect.renderSignInButton({ 'id': 'google-box',style:'long' });
+                                                }
+
+                                            };
+
+                                        }
+                                    }
+                                },{
+                                    title: 'Twitter',
+                                    collapsed: false,
+                                    hidden: true,
+                                    iconCls:'iconTwitter',
+                                    html: '<div id="twitter-box">'+
+                                             '<div id="twitter-info"></div>'+
+                                             '<div id="twitter-login"></div>'+
+                                          '</div>',
+                                    displayInfo: function(user) {
+
+                                        Ext.get('twitter-info').setVisible(true);
+
+                                        var html = '<img style="margin-right:5px" align="left" src="'+user.data('profile_image_url')+'" /> <span>'+user.data('name')+'</<span><br><a href="#" onclick="">Use this credentials</a><br><br><a href="#" onclick="twttr.anywhere.signOut(); return false;">Sign out</a><br>';
+
+                                        Ext.get('twitter-info').dom.innerHTML = html;
+
+                                        // We hide the connect button
+                                        Ext.get('twitter-login').setVisible(false);
+
+                                    },
+                                    listeners: {
+                                        resize: function(c) {
+                                            c.setHeight(100);
+                                        },
+                                        afterrender: function(cmp) {
+
+                                            Ext.get('twitter-info').setVisibilityMode(Ext.Element.DISPLAY);
+                                            Ext.get('twitter-login').setVisibilityMode(Ext.Element.DISPLAY);
+
+                                            twttr.anywhere(function (T)
+                                            {
+                                                T.bind("authComplete", function (e, user) {
+                                                    cmp.displayInfo(user);
+                                                });
+
+                                                T.bind("signOut", function (e) {
+                                                    Ext.get('twitter-login').setVisible(true);
+
+                                                    // Hide info
+                                                    Ext.get('twitter-info').setVisible(false);
+                                                });
+
+                                                if (T.isConnected())
+                                                {
+                                                    cmp.displayInfo(T.currentUser);
+
+                                                } else {
+                                                    T("#twitter-login").connectButton({ size: "large" });
+                                                }
+                                            });
+                                        }
+                                    }
+                                }]
+                            }]
                         })
                     ],
                     items : [{
@@ -136,7 +364,7 @@

                                         var url = c.store.getById('php').data.request_account_uri;
                                         Ext.get("request-account").dom.innerHTML = '<a href="' + url + '" target="_blank">' + url + '</a>';
-                                    }
+                                    }

                                 },
                                 select : function(c, record) {
@@ -161,7 +389,7 @@
                                 {
                                     var v = this.getValue(),
                                         currentLoginText = Ext.getCmp('login-btn').getText();
-
+
                                     if( v == 'anonymous' || v == '' ) {
                                         if( currentLoginText != 'Anonymous login' ) {
                                             Ext.getCmp('login-btn').setText('Anonymous login');
@@ -171,7 +399,7 @@
                                             Ext.getCmp('login-btn').setText('Login');
                                         }
                                     }
-
+
                                 },
                                 focus : function(f)
                                 {
@@ -181,7 +409,7 @@
                                         this.setValue('');
                                         Ext.getCmp('login-btn').setText('Login');
                                     }
-
+
                                 },
                                 blur : function(f)
                                 {
@@ -191,7 +419,7 @@
                                         this.setValue('');
                                         Ext.getCmp('login-btn').setText('Anonymous login');
                                     }
-
+
                                 }
                             }
                         }, {
@@ -286,8 +514,13 @@
                                     Ext.getCmp('login-form').getForm().submit({
                                         method : 'POST',
                                         params : {
+                                            vcsLogin: Ext.getCmp('login-form-vcsLogin').getValue(),
+                                            vcsPassword: Ext.getCmp('login-form-vcsPasswd').getValue(),
                                             lang    : Ext.getCmp('login-form-lang').getValue(),
-                                            project : Ext.getCmp('login-form-project').getValue()
+                                            project : Ext.getCmp('login-form-project').getValue(),
+                                            authService: PhDOE_loginPage.authService,
+                                            authServiceID: PhDOE_loginPage.authServiceID
+
                                         },
                                         waitTitle : 'Connecting',
                                         waitMsg   : 'Sending data...',
@@ -300,30 +533,16 @@
                                             if (action.response) {
                                                 var o = Ext.util.JSON.decode(action.response.responseText);

-                                                if (o.msg == 'Bad vcs password' || o.msg == 'Bad db password') {
-                                                    Ext.Msg.show({
-                                                        title   : 'Error',
-                                                        msg     : 'Bad password.<br>Please, try again.',
-                                                        buttons : Ext.Msg.OK,
-                                                        icon    : Ext.MessageBox.ERROR,
-                                                        fn      : function()
-                                                        {
-                                                            Ext.getCmp('login-form-vcsPasswd').focus();
-                                                        }
-                                                    });
-                                                }
-                                                if (o.msg == 'unknown from vcs') {
-                                                    Ext.Msg.show({
-                                                        title   : 'Error',
-                                                        msg     : 'This user is unknown to the PHP VCS server.<br>Please, try again.',
-                                                        buttons : Ext.Msg.OK,
-                                                        icon    : Ext.MessageBox.ERROR,
-                                                        fn      : function()
-                                                        {
-                                                            Ext.getCmp('login-form-vcsPasswd').focus();
-                                                        }
-                                                    });
-                                                }
+                                                Ext.Msg.show({
+                                                    title   : 'Error',
+                                                    msg     : o.msg,
+                                                    buttons : Ext.Msg.OK,
+                                                    icon    : Ext.MessageBox.ERROR,
+                                                    fn      : function()
+                                                    {
+                                                        Ext.getCmp('login-form-vcsPasswd').focus();
+                                                    }
+                                                });
                                             }
                                         }
                                     });
@@ -331,6 +550,32 @@
                                 } // validate
                             }
                         }
+                    },{
+                        scope: this,
+                        text: 'Reset',
+                        handler: function() {
+
+                            Ext.getCmp('login-form-vcsLogin').enable();
+
+                            Ext.getCmp('login-form-vcsPasswd').enable();
+                            Ext.getCmp('login-form-vcsPasswd').setValue('');
+
+                            this.authService = 'VCS';
+                            this.authServiceID = '';
+
+                            if( Ext.util.Cookies.get("loginApp") ) {
+                                Ext.getCmp('login-form-vcsLogin').setValue(Ext.util.Cookies.get("loginApp"));
+                                Ext.getCmp('login-btn').setText('Login');
+                                Ext.getCmp('login-form-email').setValue(Ext.util.Cookies.get("email"));
+
+
+                            } else {
+                                Ext.getCmp('login-form-vcsLogin').setValue('anonymous');
+                                Ext.getCmp('login-btn').setText('Anonymous login');
+                                Ext.getCmp('login-form-email').setValue('');
+                            }
+
+                        }
                     }]
                 });
             }
@@ -345,4 +590,4 @@
     };
 }();

-Ext.EventManager.onDocumentReady(PhDOE_loginPage.init, PhDOE_loginPage, true);
\ No newline at end of file
+Ext.EventManager.onDocumentReady(PhDOE_loginPage.init, PhDOE_loginPage, true);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.