public virtual async Task <HttpResponseMessage> RegisterNewUser(NewUserMessage newUserMessage) { NewUser newUser = Mapper.Map <NewUserMessage, NewUser>(newUserMessage); RegisterNewUserResult registerNewUserResult = await this.userRegisterer.RegisterUser(newUser); if (registerNewUserResult.Result.Succeeded) { string authToken = authTokenGenerator.GenerateAuthToken(registerNewUserResult.NewlyRegisteredUser.UserId); NewlyRegisteredUserMessage newlyRegisteredUserMessage = Mapper.Map <NewlyRegisteredUser, NewlyRegisteredUserMessage>(registerNewUserResult.NewlyRegisteredUser); newlyRegisteredUserMessage.AuthenticationToken = authToken; return(Request.CreateResponse(HttpStatusCode.OK, newlyRegisteredUserMessage)); } return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, registerNewUserResult.Result.Errors.First())); }
public async Task <HttpResponseMessage> Login(CredentialsMessage credentialsMessage) { var user = await applicationUserManager.FindAsync(credentialsMessage.UserName, credentialsMessage.Password); if (user == null) { return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Invalid credentials provided.")); } NewAuthTokenMessage newAuthTokenMessage = new NewAuthTokenMessage { AuthenticationToken = authTokenGenerator.GenerateAuthToken(user.Id) }; return(Request.CreateResponse(HttpStatusCode.OK, newAuthTokenMessage)); }
public virtual async Task <HttpResponseMessage> RegisterNewUser(NewUserMessage newUserMessage) { var newUser = Mapper.Map <NewUserMessage, NewUser>(newUserMessage); var registerNewUserResult = await _userRegisterer.RegisterUser(newUser); if (registerNewUserResult.Result.Succeeded) { var authToken = _authTokenGenerator.GenerateAuthToken(registerNewUserResult.NewlyRegisteredUser.UserId, newUserMessage.UniqueDeviceId); var newlyRegisteredUserMessage = Mapper.Map <NewlyRegisteredUser, NewlyRegisteredUserMessage>(registerNewUserResult.NewlyRegisteredUser); newlyRegisteredUserMessage.AuthenticationToken = authToken.AuthenticationTokenString; newlyRegisteredUserMessage.AuthenticationTokenExpirationDateTime = authToken.AuthenticationTokenExpirationDateTime; return(Request.CreateResponse(HttpStatusCode.OK, newlyRegisteredUserMessage)); } return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, registerNewUserResult.Result.Errors.First())); }