コード例 #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
ファイル: AdzbuzzOAuth.cs プロジェクト: dovanduy/titan
        public static void GetTokenAndLogin(string code, string state)
        {
            if (HttpContext.Current.Session != null && HttpContext.Current.Session[SessionStateKey] != null &&
                HttpContext.Current.Session[SessionStateKey].ToString() != state)
            {
                throw new Exception("Invalid OAuth state.");
            }

            string accessToken =
                OAuth2.AuthenticateByCode(GetProvider(state), HandlerUrl, code).AccessToken;

            string userInfoString = OAuth2.GetUserInfo(GetProvider(state), accessToken);

            JObject UserInfo   = JObject.Parse(userInfoString);
            JToken  UserObject = UserInfo["userObj"];

            string username = UserObject["id"].ToString();

            if (!Member.Exists(username))
            {
                //Register

                string   email     = UserObject["email"].ToString();
                DateTime birthYear = new DateTime((int)UserObject["birth"]["year"], 1, 1);

                TitanRegisterService.Register(username, email, 1234, birthYear,
                                              HashingManager.GenerateMD5(DateTime.Now + username), String.Empty, Gender.Male, null, String.Empty,
                                              String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, true, false, false, null, true);
            }

            Member member = new Member(username);

            member = MemberAuthenticationService.CreateAuthCredentials(member);

            member.BirthYear  = new DateTime((int)UserObject["birth"]["year"], 1, 1);
            member.FirstName  = UserObject["first_name"].ToString();
            member.SecondName = UserObject["last_name"].ToString();
            member.AvatarUrl  = UserObject["avatar_url"].ToString();

            NotNullNameValuePairs nvp = new NotNullNameValuePairs();

            nvp.Add("adzbuzz_affid", UserObject["affid"].ToString());
            nvp.Add("adzbuzz_userid", UserObject["id"].ToString());

            member.Custom = nvp;

            member.Save();

            TitanAuthService.AuthenticateWithChecks(member, false, true);
        }
コード例 #3
0
ファイル: Login.ascx.cs プロジェクト: dovanduy/titan
 protected void ReactivateButton_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         try
         {
             TitanAuthService.Reactivate(Username.Text, Password.Text, Password2.Text);
         }
         catch (MsgException ex)
         {
             FailureP.Visible = true;
             FailureText.Text = ex.Message;
             FormsAuthentication.SignOut();
         }
         catch (Exception ex)
         {
             ErrorLogger.Log(ex);
             throw ex;
         }
     }
 }
コード例 #4
0
ファイル: Login.ascx.cs プロジェクト: dovanduy/titan
    protected void LoginButton_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            try
            {
                TitanAuthService.Login(Username.Text, Password.Text, Password2.Text);
            }
            catch (SpecialException ex)
            {
                //Account inctive
                if (ReactivationEnabled)
                {
                    ReactivateButton.Visible = true;
                    LoginButton.Visible      = false;
                }
                FailureP.Visible = true;
                FailureText.Text = ex.Message;
                FormsAuthentication.SignOut();
            }
            catch (MsgException ex)
            {
                FailureP.Visible = true;
                FailureText.Text = ex.Message;
                FormsAuthentication.SignOut();

                if (ex.Message == L1.ACCNOTACTIVATED)
                {
                    FailureText.Text += " " + U6006.CLICKBUTTONBELOW;
                    ShowResendActivationControls();
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.Log(ex);
                throw ex;
            }
        }
    }
コード例 #5
0
ファイル: Login.ascx.cs プロジェクト: dovanduy/titan
    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;
        }
    }