Exemple #1
0
 public TransitOpenIdLogin TryLoginOpenId(string token, string[] names, string[] values)
 {
     using (SnCore.Data.Hibernate.Session.OpenConnection())
     {
         ISession session = SnCore.Data.Hibernate.Session.Current;
         TransitOpenIdLogin t_result = new TransitOpenIdLogin();
         ManagedOpenIdLogin t_login = ManagedAccount.TryLoginOpenId(session, token, new NameValueCollectionSerializer(names, values).Collection);
         t_result.ConsumerUrl = t_login.ConsumerUri.ToString();
         if (t_login.Account != null)
         {
             string ticket = ManagedAccount.GetTicketFromAccount(t_login.Account);
             SnCore.Data.Hibernate.Session.Flush();
             t_result.Ticket = ticket;
         }
         return t_result;
     }
 }
    public void Page_Load(object sender, EventArgs e)
    {
        try
        {
            PageManager.SetDefaultButton(loginLogin, Controls);

            if (!IsPostBack)
            {
                linkAdministrator.OnClientClick =
                    string.Format("location.href='mailto:{0}';",
                                  SessionManager.GetCachedConfiguration(
                                      "SnCore.Admin.EmailAddress", "*****@*****.**"));

                FacebookPageManager facebook = new FacebookPageManager(SessionManager);

                if (string.IsNullOrEmpty(facebook.FacebookAPIKey))
                {
                    panelFacebookLogin.Visible    = false;
                    facebookLoginDisabled.Visible = true;
                }

                string openidmode  = Request["openid.mode"];
                string openidtoken = SessionManager.OpenIdToken;
                if (!string.IsNullOrEmpty(openidmode) && !string.IsNullOrEmpty(openidtoken))
                {
                    NameValueCollectionSerializer serializer = new NameValueCollectionSerializer(Request.Params);
                    TransitOpenIdLogin            t_login    = SessionManager.AccountService.TryLoginOpenId(openidtoken, serializer.Names, serializer.Values);
                    if (!string.IsNullOrEmpty(t_login.Ticket))
                    {
                        SessionManager.Login(t_login.Ticket, SessionManager.RememberLogin);
                        Redirect(ReturnUrl);
                    }
                    else
                    {
                        Redirect(string.Format("AccountCreateOpenId.aspx?ReturnUrl={0}&ConsumerUrl={1}",
                                               Renderer.UrlEncode(ReturnUrl), Renderer.UrlEncode(t_login.ConsumerUrl)));
                    }
                }

                string facebookConnect = Request["connect"];
                if (!string.IsNullOrEmpty(facebookConnect))
                {
                    SortedList <string, string> facebookCookies = facebook.GetFacebookCookies(HttpContext.Current.Request.Cookies);
                    List <String>        keys    = new List <String>(facebookCookies.Keys);
                    List <String>        values  = new List <String>(facebookCookies.Values);
                    TransitFacebookLogin t_login = SessionManager.AccountService.TryLoginFacebook(
                        HttpContext.Current.Request.Cookies[facebook.FacebookAPIKey].Value, keys.ToArray(), values.ToArray());

                    if (string.IsNullOrEmpty(t_login.Ticket))
                    {
                        Redirect("AccountCreateFacebook.aspx?connect=1");
                        return;
                    }

                    SessionManager.Login(t_login.Ticket, SessionManager.RememberLogin);
                    Redirect(ReturnUrl);
                }

                if (SessionManager.IsLoggedIn)
                {
                    ReportInfo("You're already logged-in. Click <a href='AccountManage.aspx'>here</a> to continue.", false);
                    loginLogin.Enabled = false;
                }
            }
        }
        catch
        {
            SessionManager.Logout();
            throw;
        }
    }