public async Task <IHttpActionResult> SignUp([FromBody] CreateUserRequest apiRequest) { try { if (apiRequest == null) { return(Ok(new ResultDetail(ErrorConstants.InvalidPropertyValue, "Empty required fields", null))); } if (string.IsNullOrEmpty(apiRequest.Name)) { return(Ok(new ResultDetail(ErrorConstants.InvalidPropertyValue, "Name is required", null))); } if (string.IsNullOrEmpty(apiRequest.Email)) { return(Ok(new ResultDetail(ErrorConstants.InvalidPropertyValue, "Email is required", null))); } if (string.IsNullOrEmpty(apiRequest.Password)) { return(Ok(new ResultDetail(ErrorConstants.InvalidPropertyValue, "Password is required", null))); } if (apiRequest.RoleID == 0) { return(Ok(new ResultDetail(ErrorConstants.InvalidPropertyValue, "RoleId is required", null))); } var result = (await RespositoryService.UserService.CreateUser(apiRequest)).ResponseObject; if (result < 0) { return(Ok(new ResultDetail(result, ErrorConstants.ErrorDescription(result), Version, result))); } var response = new ResultDetail(ErrorConstants.Success, "Success", Version, result); return(Ok(response)); }catch (Exception ex) { throw new AppHttpException(HttpStatusCode.OK , new ResultDetail(ErrorConstants.Unknown, ex.Message, Version)); } }
public async Task <IHttpActionResult> Login([FromBody] UserRequest apiRequest) { try { if (string.IsNullOrEmpty(apiRequest.Email)) { return(Ok(new ResultDetail(ErrorConstants.InvalidPropertyValue, "Email is required", null))); } if (string.IsNullOrEmpty(apiRequest.Password)) { return(Ok(new ResultDetail(ErrorConstants.InvalidPropertyValue, "Password is required", null))); } var result = (await RespositoryService.UserService.GetUser(apiRequest)).ResponseObject; if (result == null) { return(Ok(new ResultDetail(ErrorConstants.Unknown, "User not found", Version, result))); } if (!result.Password.ToUpper().Equals(ConfigHelpers.EncryptStringMD5(apiRequest.Password).ToUpper())) { return(Ok(new ResultDetail(ErrorConstants.WRONG_USER_AUTHENTICATION, ErrorConstants.ErrorDescription(ErrorConstants.WRONG_USER_AUTHENTICATION), Version, null))); } JwtManager jwtManager = new JwtManager(); TokenRequest tokenRequest = new TokenRequest(); tokenRequest.UserID = result.ID; tokenRequest.Name = result.Name; tokenRequest.Email = result.Email; tokenRequest.RoleID = result.RoleID; var token = jwtManager.GenerateSecurityToken(tokenRequest); token.UserDetail = result; var response = new ResultDetail(ErrorConstants.Success, "Success", Version, token); return(Ok(response)); }catch (Exception ex) { throw new AppHttpException(HttpStatusCode.OK , new ResultDetail(ErrorConstants.Unknown, ex.Message, Version)); } }