예제 #1
0
    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;
        }
    }
예제 #2
0
 public TransitFacebookLogin TryLoginFacebook(string signature, string[] names, string[] values)
 {
     using (SnCore.Data.Hibernate.Session.OpenConnection())
     {
         ISession session = SnCore.Data.Hibernate.Session.Current;
         TransitFacebookLogin t_result = new TransitFacebookLogin();
         ManagedFacebookLogin t_login = ManagedAccount.TryLoginFacebook(session, signature,
             new NameValueCollectionSerializer(names, values).Collection);
         t_result.FacebookAccountId = t_login.FacebookAccountId;
         if (t_login.Account != null)
         {
             string ticket = ManagedAccount.GetTicketFromAccount(t_login.Account);
             SnCore.Data.Hibernate.Session.Flush();
             t_result.Ticket = ticket;
         }
         return t_result;
     }
 }
예제 #3
0
    public void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            FacebookPageManager facebook = new FacebookPageManager(SessionManager);
            if (string.IsNullOrEmpty(facebook.FacebookAPIKey))
            {
                throw new Exception("This site is not configured for Facebook login: missing Facebook API key.");
            }

            if (!string.IsNullOrEmpty(Request["betapassword"]))
            {
                inputBetaPassword.Attributes["value"] = Request["betapassword"];
            }

            panelBeta.Visible = SessionManager.AccountService.IsBetaPasswordSet();

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

            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))
                {
                    ReportInfo(string.Format("An account for the Facebook user id \"{0}\" already exists." +
                                             "<br />Please <a href='AccountLogin.aspx'>click here to log-in</a> instead.",
                                             facebookCookies["user"]), false);

                    panelFacebook.Visible = false;
                    return;
                }

                int id = SessionManager.AccountService.CreateAccountWithFacebook(
                    inputBetaPassword.Text,
                    HttpContext.Current.Request.Cookies[facebook.FacebookAPIKey].Value,
                    keys.ToArray(),
                    values.ToArray());

                string ticket = ManagedAccount.GetTicketFromAccountId(id);
                SessionManager.Login(ticket, false);
                Redirect("AccountCreateWelcome.aspx");
                return;
            }
            else
            {
                panelFacebook.Visible = true;
            }

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