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); }
protected void CreateUserButton_Click(object sender, EventArgs e) { ErrorMessagePanel.Visible = false; if (Page.IsValid) { try { DateTime InBirthYear = new DateTime(Int32.Parse(BirthYear.Text.Trim()), 1, 1); Gender InGender = GenderList.SelectedValue == "1" ? Gender.Male : Gender.Female; Panel CustomFields = this.CustomFields; int InPIN = AppSettings.Registration.IsPINEnabled ? Int32.Parse(PIN.Text.Trim()) : 9999; if (IsFromFacebookOAuth) { //Facebook register procedure string accessToken = Session["accessToken"].ToString(); FacebookMember fbMember = new FacebookMember(accessToken); TitanRegisterService.Register(Username.Text.Trim(), Email.Text.Trim(), InPIN, InBirthYear, accessToken, Referer.Text.Trim(), fbMember.Gender, CustomFields, FirstName.Text, SecondName.Text, Address.Text, City.Text, StateProvince.Text, ZipCode.Text, EarnerCheckBox.Checked, AdvertiserCheckBox.Checked, PublisherCheckBox.Checked, fbMember.FacebookId); } else { //Standard register procedure TitanRegisterService.Register(Username.Text.Trim(), Email.Text.Trim(), InPIN, InBirthYear, Password.Text.Trim(), Referer.Text.Trim(), InGender, CustomFields, FirstName.Text, SecondName.Text, Address.Text, City.Text, StateProvince.Text, ZipCode.Text, EarnerCheckBox.Checked, AdvertiserCheckBox.Checked, PublisherCheckBox.Checked); } } catch (MsgException ex) { ErrorMessagePanel.Visible = true; ErrorMessage.Text = ex.Message; } catch (Exception ex) { ErrorLogger.Log(ex); throw ex; } } }
public static Member GetMember(MemberAuthenticationData authData) { var requestParams = new NVPStringBuilder() .Append("operation", "login") .Append("username", authData.Username) .Append("password", authData.PrimaryPassword) .Append("domain", "WS_INTEGRATION_ACCESS") .Build(); var jsonResponse = S4DSAPI.SendRequest("rest/AuthService", requestParams); S4DSAuthInfo AuthInfo = new S4DSAuthInfo(jsonResponse); if (!AuthInfo.IsOK) { throw new MsgException("Unable to log in using those credentials."); } if (!Member.Exists(authData.Username)) { //Register TitanRegisterService.Register(authData.Username, authData.Username, 1234, new DateTime(1980, 1, 1), authData.PrimaryPassword, String.Empty, Gender.Male, null, String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, true, false, false, null, true); } Member Result = new Member(authData.Username); S4DSAuthenticationInformation.AddOrUpdate(Result.Id, AuthInfo); Result.S4DSPackages = GetMemberPackages(AuthInfo); Result.SaveCustomFeatures(); //if (Result.S4DSPackages == 0) // throw new MsgException("You cannot login because you have 0 packages."); return(Result); }