public async Task <HttpResponseMessage> AddOneMember([FromBody] AccountInfo mai) { try { mai._password = UIHelperController.EncryptDataMD5(mai._password); await AccountInfoWorkFlow.CreateMemberAccount(mai); var message = Request.CreateResponse(HttpStatusCode.Created, mai); message.Headers.Location = new Uri(Request.RequestUri + " added account: " + mai._email); return(message); } catch (Exception e) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e)); } }
public IHttpActionResult MemberAuthenticate([FromBody] AccountInfo mai) { var loginResponse = new HttpResponseMessage { }; AccountInfo AccountInfo = new AccountInfo(); IHttpActionResult response; HttpResponseMessage responseMsg = new HttpResponseMessage(); bool isUsernamePasswordValid = false; if (mai != null) { AccountInfo._email = mai._email; AccountInfo._password = mai._password; List <AccountInfo> lstAccount = new List <AccountInfo>(); lstAccount = AccountInfoWorkFlow.GetMemberAccountLoginInfo(AccountInfo._email, UIHelperController.EncryptDataMD5(AccountInfo._password)); if (lstAccount.Count > 0) { isUsernamePasswordValid = true; } } // if credentials are valid if (isUsernamePasswordValid) { string token = CreateToken(AccountInfo._email); //return the token return(Ok <string>(token)); } else { // if credentials are not valid send unauthorized status code in response loginResponse.StatusCode = HttpStatusCode.Unauthorized; response = ResponseMessage(loginResponse); return(response); } }