public AccountToken(DateTimeOffset issued, DateTimeOffset expires, AccountTokenType type, string value) { Issued = issued; Expires = expires; Type = type; Value = value; }
/// <summary> /// Creates a new account using the specified username, provider token, password, and email /// </summary> /// <param name="username"></param> /// <param name="tokenType"></param> /// <param name="token"></param> /// <param name="password"></param> /// <param name="email"></param> /// <param name="loginWhenComplete"></param> /// <param name="options">The options for this request</param> /// <returns></returns> public async Task CreateAccountAsync(string username, AccountTokenType tokenType, string token, string password = null, string email = null, bool loginWhenComplete = true, RequestOptions options = null) { AccountCreationRequest request = new AccountCreationRequest() { Username = username, Password = password, Email = email, }; switch (tokenType) { case AccountTokenType.FacebookAuthCode: request.Provider = FacebookProvider; request.AuthCode = token; break; case AccountTokenType.FacebookAccessToken: request.Provider = FacebookProvider; request.AccessToken = token; break; case AccountTokenType.TwitterToken: request.Provider = TwitterProvider; request.Token = token; break; case AccountTokenType.TwitterVerifier: request.Provider = TwitterProvider; request.Verifier = token; break; case AccountTokenType.TwitterOauthToken: request.Provider = TwitterProvider; request.OauthToken = token; break; case AccountTokenType.TwitterOauthTokenSecret: request.Provider = TwitterProvider; request.OauthTokenSecret = token; break; } ClientAccountAuthResponse response = await ApiClient.CreateAccountAsync(request, options).ConfigureAwait(false); if (loginWhenComplete) { AccessToken = response.AccessToken; RefreshToken = response.RefreshToken; } }
public async Task <IActionResult> VerifyAccountToken([FromBody] dynamic param = null) { string tokenValue = null; AccountToken accountToken = null; object result = null; try { tokenValue = param.tokenValue; AccountTokenType type = (AccountTokenType)((short)param.accountType); accountToken = await GetAccountToken(tokenValue, type); switch (type) { case AccountTokenType.EmailChange: accountToken.Account.RegisterForRecordStateChange(); accountToken.Account.Email = accountToken.AddData; accountToken.Account.EmailConfirmed = true; accountToken.Account.UnregisterForRecordStateChange(); accountToken.RecordState = RecordState.Deleted; _dbi.ManageIdentityModels(accountToken.Account, accountToken); break; case AccountTokenType.SignUp: result = accountToken.Account.ToModel(); break; } return(Json(new { Ok = true, result = result })); } catch (Exception ex) { return(InternalServerError(ex)); } finally { tokenValue = null; accountToken = null; result = null; } }
protected async Task <Data.Account> Register(string accountName, string name, AccountTokenType type, bool id_affiliate, string globalId = "") { if (!accountName.HasValue()) { throw new AccountTokenInvalidException(); } if (!IsTokenUniqueAsync(accountName).Result) { throw new AccountNotUniqueException(); } Data.Account account = new Data.Account { GlobalId = (globalId.HasValue()) ? globalId : Guid.NewGuid().ToString(), WhenCreated = DateTime.UtcNow, WhenAuthenticated = DateTime.UtcNow }; if (!await HasAccounts()) { account.Role = AccountRole.Administrator; } await _store.Add(account); account.Tokens.Add(new Data.AccountToken { Hash = accountName.ToNormalizedSha256(), WhenCreated = DateTime.UtcNow, Type = type }); await _store.Update(account); if (_options.Registration.StoreName) { await SetAccountNames(account, name, id_affiliate); } await _profileService.AddProfileAsync(account.GlobalId, name); return(account); }
private async Task <AccountToken> GetAccountToken(string tokenValue, AccountTokenType accountTokenType) { AccountToken accountToken = null; Account account = null; SysParDetailValue sysParValue = null; Exception ex1 = null, ex2 = null; try { await Task.WhenAll( Helper.GetFunc(() => { try { accountToken = _dbi.GetAccountToken(tokenValue, type: accountTokenType); } catch (Exception ex) { ex1 = ex; } return(Task.CompletedTask); })(), Helper.GetFunc(() => { string detailCode = null; try { switch (accountTokenType) { case AccountTokenType.EmailChange: case AccountTokenType.SignUp: detailCode = "SignUpTokenLifeSpan"; break; case AccountTokenType.ResetPassword: detailCode = "ResetPasswordLifeSpan"; break; } if (string.IsNullOrEmpty(detailCode)) { throw new ExceptionID(MessageIdentifier.TOKEN_SYS_PARS_NOT_FOUND); } sysParValue = _dbi.GetSysParDetailValue(masterCode: "TokenParams", detailCode: detailCode); } catch (Exception ex) { ex2 = ex; } return(Task.CompletedTask); })()); if (ex1 != null) { throw ex1; } if (ex2 != null) { throw ex2; } if (sysParValue == null) { throw new ExceptionID(MessageIdentifier.TOKEN_SYS_PARS_NOT_FOUND); } if (accountToken == null || accountToken.Account_Id == null || accountToken.Account_Id <= 0) { throw new ExceptionID(MessageIdentifier.TOKEN_NOT_FOUND); } if (accountToken.CreationTimeUtc.AddSeconds(sysParValue.IntVal.Value) < DateTimeOffset.UtcNow) { throw new ExceptionID(MessageIdentifier.ACCOUNT_CONNECTION_TOKEN_EXPIRED); } account = _dbi.GetAccount(accountToken.Account_Id.Value, null, null, null, includeSignUpToken: (accountTokenType == AccountTokenType.SignUp)); accountToken.Account = account ?? throw new ExceptionID(MessageIdentifier.TOKEN_NOT_FOUND); return(accountToken); } catch (Exception ex) { throw ex; } finally { accountToken = null; account = null; sysParValue = null; ex1 = null; ex2 = null; } }