コード例 #1
0
    public async Task <IHttpActionResult> GetPasscode(string email)
    {
        ApplicationUser user = await AppUserManager.FindByEmailAsync(email);

        if (user == null)
        {
            return(BadRequest());
        }
        string code = PassCode.GeneratePresharedKey();

        user.PasscodeHash      = code;
        user.LockoutEndDateUtc = DateTime.UtcNow.AddMinutes(30);
        IdentityResult userResult = await this.AppUserManager.UpdateAsync(user);

        if (!userResult.Succeeded)
        {
            return(GetErrorResult(userResult));
        }
        await this.AppUserManager.SendEmailAsync(user.Id, "Login Passcode", code);

        return(Ok());
    }