예제 #1
0
    protected override ApiResultMessage HandleRequest(object args)
    {
        var    data = ((JObject)args).ToObject <ApiAuthenticationData>();
        Member user = null;

        if (!data.isFacebook)
        {
            //Standard login procedure
            TitanAuthService.Login(data.username, data.password, data.secondaryPassword, false);
            user = new Member(data.username);
        }
        else
        {
            //Facebook login procedure
            FacebookMember fbUser = new FacebookMember(data.username);
            TitanAuthService.LoginOrRegister(fbUser, false);
            user = TableHelper.SelectRows <Member>(TableHelper.MakeDictionary("FacebookOAuthId", fbUser.FacebookId))[0];
        }

        var token = ApiAccessToken.GetOrCreate(user.Id);

        return(new ApiResultMessage
        {
            success = true,
            message = String.Empty,
            data = new JObject(new JProperty("token", token.Token))
        });
    }
예제 #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (AppSettings.Authentication.LoginUsingEmail)
        {
            Username.Attributes.Add("PlaceHolder", "Email");
        }
        else
        {
            Username.Attributes.Add("PlaceHolder", L1.USERNAME);
        }

        if (AppSettings.Authentication.ResetPasswordAndPinTogether)
        {
            ForgotMyPasswordHyperLink.Text = L1.IFORGOTPWD + "/PIN";
        }
        else
        {
            ForgotMyPasswordHyperLink.Text = L1.IFORGOTPWD;
        }

        //Facebook OAuth
        if (Request.QueryString["fb"] != null && Request["accessToken"] != null)
        {
            var accessToken = Request["accessToken"];
            Session["AccessToken"] = accessToken;
            try
            {
                FacebookMember User = new FacebookMember(accessToken);
                TitanAuthService.LoginOrRegister(User);
            }
            catch (MsgException ex)
            {
                FailureP.Visible = true;
                FailureText.Text = ex.Message;
                FormsAuthentication.SignOut();
            }
            catch (Exception ex)
            {
                ErrorLogger.Log(ex);
                throw ex;
            }
        }

        //Demo autofill
        if (AppSettings.IsDemo)
        {
            Username.Text = "demo";
            Password.Text = "demopassword";
            System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "document.getElementById('" + Password.ClientID + "').value = 'demopassword';", true);
        }

        //General autofill
        if (Request.QueryString["username"] != null && Request.QueryString["password"] != null)
        {
            string username = HttpUtility.UrlDecode(Request.QueryString["username"]);
            string password = HttpUtility.UrlDecode(Request.QueryString["password"]);

            Username.Text = username;
            Password.Text = password;

            System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "document.getElementById('" + Password.ClientID + "').value = '" + password + "';", true);
        }

        //Add label & hint translations
        HintAdder.Add(Password2, L1.LEAVEBLANKIFNOTPWD2);
        LangAdder.Add(LoginButton, U4000.LOGINTEXT);
        LangAdder.Add(CustomValidator1, L1.ER_BADCAPTCHA);
        LoginUserValidationSummary.HeaderText = L1.ER_ALLFIELDSREQUIRED;

        //Check wheather we should request Captcha (two bad logins trials)
        if (MemberAuthenticationService.GetBadLoginTrials(Context) > 1)
        {
            CaptchaPanel1.Visible = true;
            LoginUserValidationSummary.HeaderText = L1.ER_ALLFIELDSREQUIRED2;
        }

        if (Request.QueryString["afterregister"] != null && Convert.ToInt32(Request.QueryString["afterregister"]) == 1)
        {
            ShowResendActivationControls(true);
            ResendEmailButton.Visible = false;
        }
    }