/// <summary> /// 確認信箱 /// </summary> /// <param name="d"></param> /// <returns></returns> public BaseResult ConfirmEmail(string d) { var result = new BaseResult { RtnMsg = "驗證失敗,請重新再試。" }; var model = decryptObject <ValidateToken>(d); if (model == null || !validUserToken(model.UserId, UserTokens.ConfirmEmail, model.Token, out DateTime expiredDT)) { return(result); } using (var scope = new TransactionScope()) { // 驗證信箱 confirmEmail(model.UserId, model.Email); // 移除驗證金鑰 removeUserToken(model.UserId, UserTokens.ConfirmEmail); scope.Complete(); } return(BaseResult.Ok()); }
/// <summary> /// 修改密碼 /// </summary> /// <param name="userId"></param> /// <param name="password"></param> /// <returns></returns> public BaseResult ChangePassword(long userId, string password) { string hashPassword = _cryptHelper.HashPassword(password); using (var scope = new TransactionScope()) { // 修改密碼 changePassword(userId, hashPassword); // 移除驗證金鑰(撤回先前發布的重設密碼金鑰) removeUserToken(userId, UserTokens.ResetPassword); scope.Complete(); } return(BaseResult.Ok()); }
/// <summary> /// 驗證金鑰 /// </summary> /// <param name="model"></param> /// <returns></returns> public BaseResult ValidateToken(string type, string d, out long userId) { var result = new BaseResult { RtnMsg = "驗證失敗,請重新再試。" }; userId = 0; var model = decryptObject <ValidateToken>(d); if (model == null || !validUserToken(model.UserId, type, model.Token, out DateTime expiredDT)) { return(result); } userId = model.UserId; return(BaseResult.Ok()); }
/// <summary> /// 登入 /// </summary> /// <param name="account"></param> /// <param name="password"></param> /// <returns></returns> public BaseResult Login(string account, string password, bool isPersistent) { BaseResult result = new BaseResult { RtnMsg = "登入失敗,帳號或密碼錯誤。" }; if (!validAccount(account, password, out User user)) { return(result); } string token = generateUserToken(user.Id, UserTokens.Login, _setting.LoginTokenPeriod, _setting.MaxLoginCount); writeLoginCookie(new UserData { Id = user.Id, DisplayName = user.DisplayName, LoginToken = token, IsPersistent = isPersistent }); return(BaseResult.Ok()); }