public async Task <ActionResult> Register(AccountRegisterViewModel registerVm) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var identityResult = await _accountManager.Register(registerVm.FirstName, registerVm.LastName, registerVm.Email, registerVm.Password); if (!identityResult.Succeeded) { var error = identityResult.Errors.Any() ? identityResult.Errors.FirstOrDefault().Description : "Error while registering user!"; return(BadRequest(error)); } var user = await _accountManager.Authenticate(registerVm.Email, registerVm.Password, false); if (user == null) { return(Unauthorized()); } var identity = await GetClaimsIdentity(user); var response = new { uId = identity.Claims.Single(c => c.Type == "id").Value, firstName = user.FirstName, lastName = user.LastName, email = user.Email, formattedName = user.FirstName + " " + user.LastName, auth_token = await _jwtFactory.GenerateEncodedToken(user.Email, identity), expires_in = (int)_jwtOptions.ValidFor.TotalSeconds }; var userData = JsonConvert.SerializeObject(response); return(new OkObjectResult(userData)); } catch (Exception ex) { await _logger.Log(LogLevel.Error, "Account", ex, "Register"); return(new BadRequestObjectResult(ex.Message)); } }
public Business Authenticate(string email, string password) { if (String.IsNullOrEmpty(email) || String.IsNullOrEmpty(password)) { return(null); } return(_accountManager.Authenticate(email, password, _repository)); }
public User Authenticate(string email, string password) { if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) { return(null); } return(_accountManager.Authenticate(email, password, _userRepository)); }