Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            user = DataObject.Load <DataObjectUser>(UserProfile.Current.UserId, null, true);
            if (user.State != ObjectState.Added)
            {
                if (!string.IsNullOrEmpty(user.OpenID))
                {
                    this.LitOpenIDCur.Text = user.OpenID;
                }
                else
                {
                    this.LitOpenIDCur.Text = language.GetString("MessageOpenIdNone");
                }
            }

            if (!IsPostBack)
            {
                OpenIdClient openID = new OpenIdClient();

                switch (openID.RequestedMode)
                {
                case RequestedMode.IdResolution:
                    openID.Identity = UserProfile.Current.OpenID;
                    if (openID.ValidateResponse())
                    {
                        OpenIdUser openIDUser = openID.RetrieveUser();
                        user.OpenID = openIDUser.Identity;
                        user.Update(UserDataContext.GetUserDataContext());
                        UserProfile.Current.OpenID = string.Empty;
                        UserProfile.Current.Save();
                        this.LitOpenIDMsg.Text = language.GetString("MessageOpenIdConfirmed");
                        this.LitOpenIDCur.Text = user.OpenID;
                    }
                    else
                    {
                        this.LitOpenIDMsg.Text = language.GetString("MessageOpenIdNotConfirmed");
                    }
                    break;

                case RequestedMode.CanceledByUser:
                    this.LitOpenIDMsg.Text = language.GetString("MessageOpenIdCanceled");
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        private void HandleOpenIDLogin()
        {
            OpenIdClient openID = new OpenIdClient();

            switch (openID.RequestedMode)
            {
            case RequestedMode.IdResolution:
                openID.Identity = UserProfile.Current.OpenID;
                if (openID.ValidateResponse())
                {
                    OpenIdUser openIDUser = openID.RetrieveUser();
                    UserProfile.Current.OpenID = string.Empty;
                    UserProfile.Current.Save();
                    CSBooster_DataContext csb = new CSBooster_DataContext(Helper.GetSiemeConnectionString());
                    var user = csb.hisp_DataObject_GetUserIDByOpenID(openIDUser.Identity).ElementAtOrDefault(0);
                    if (user != null)     // User exists
                    {
                        MembershipUser membershipUser = Membership.GetUser(user.USR_ID);
                        if (membershipUser != null)
                        {
                            PerformLogin(membershipUser.UserName);
                        }
                    }
                    else     // User doesn't exist
                    {
                        string nickname  = openIDUser.GetValue("openid.sreg.nickname");
                        string email     = openIDUser.GetValue("openid.sreg.email");
                        string fullname  = openIDUser.GetValue("openid.sreg.fullname") ?? nickname;
                        string gender    = openIDUser.GetValue("openid.sreg.gender");
                        string firstname = string.Empty;
                        string lastname  = string.Empty;

                        if (!string.IsNullOrEmpty(nickname) && !string.IsNullOrEmpty(email))
                        {
                            string[] splitFullname = fullname.Split(' ');
                            if (splitFullname.Length > 0)
                            {
                                firstname = splitFullname[0];
                            }
                            if (splitFullname.Length > 1)
                            {
                                lastname = splitFullname[1];
                            }

                            if (DataObjectUser.CreateUser(AuthenticationType.OpenID, openIDUser.Identity, nickname, email, firstname, lastname, gender))
                            {
                                PerformLogin(nickname);
                            }
                        }
                        else
                        {
                            LitOpenIDMsg.Text = language.GetString("MessageOpenIDNoDataReceived");
                        }
                    }
                }
                else
                {
                    LitOpenIDMsg.Text = language.GetString("MessageOpenIDLoginNotSuccess");
                }
                break;

            case RequestedMode.CanceledByUser:
                LitOpenIDMsg.Text = language.GetString("MessageOpenIDLoginCancel");
                break;
            }
        }