Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
    public static void Save(Member User, Panel page, bool isFromSurvey = false)
    {
        if (!AppSettings.Authentication.CustomFieldsAsSurvey || isFromSurvey)
        {
            var Fields = TableHelper.SelectRows <Titan.CustomRegistrationField>(TableHelper.MakeDictionary("IsHidden", false));
            NotNullNameValuePairs nvp = new NotNullNameValuePairs();

            foreach (var Field in Fields)
            {
                if (Field.Type == RegistrationFieldType.TextBox)
                {
                    nvp.Add(Field.StringID, ((TextBox)page.FindControl(customFieldPrefix + Field.StringID)).Text);
                }
                else if (Field.Type == RegistrationFieldType.CheckBox)
                {
                    nvp.Add(Field.StringID, ((CheckBox)page.FindControl(customFieldPrefix + Field.StringID)).Checked.ToString());
                }
            }
            User.Custom = nvp;
        }
    }