コード例 #1
0
 public async Task<IActionResult> SignIn(SigninModel credentials)
 {
     if (!ModelState.IsValid)
     {
         return HttpBadRequest(ModelState);
     }
     try {
         AccessTokenResponse response = new AccessTokenResponse();// await AuthHelper.Login(Url, credentials.Email, credentials.Password);
         if (!response.success)
         {
             return GenerateErrorResult(response);
         }
         return Ok(response);
     } catch (Exception ex)
     {
         return GenerateErrorResult("An unknown error occurred");
     }
 }
コード例 #2
0
        public async Task<IActionResult> Register(RegisterModel userModel)
        {
            if (!ModelState.IsValid)
            {
                return HttpBadRequest(ModelState);
            }

            try
            {
                var temp = new AccessTokenResponse
                {
                    access_token = "sdfsdf",
                    userId = "robin"
                };
                return Ok(temp);

                var user = new ApplicationUser
                {
                    UserName = userModel.UserName,
                    Email = userModel.UserName,
                };
                var result = await _userManager.CreateAsync(user, userModel.Password);
                
                
                if(!result.Succeeded)
                {
                    return GenerateErrorResult(result);
                }
                

                await SendEmailConfirmationTokenAsync(user);

                var response = new AccessTokenResponse();// await AuthHelper.Login(Url, userModel.UserName, userModel.Password);
                return Ok(response);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", "An unknown error occurred");
                return HttpBadRequest(ModelState);
            }
        }
コード例 #3
0
 private IActionResult GenerateErrorResult(AccessTokenResponse response)
 {
     ModelState.AddModelError("", !string.IsNullOrEmpty(response.error_description) ? response.error_description : response.error);
     return HttpBadRequest(ModelState);
 }