public IHttpActionResult LoginWithLoginCredentials([FromBody] LoginCredentialLoginForm request) { var _loginType = request._loginType; string _password = request._password; string _username = request._username; LoginCredential LoginCredential = null; var _contextIncluded = _context.LoginCredentials .Include("User") .Include("User.UserCommunicationPreferences") .Include("User.UserFarms") .Include("User.UserFarms.Farm"); if (_loginType == "Email") { LoginCredential = _contextIncluded. Where(x => x.Password.Equals(_password) && x.User.UserEmail == _username).FirstOrDefault(); } else if (_loginType == "PhoneNumber") { LoginCredential = _contextIncluded. Where(x => x.Password.Equals(_password) && x.User.UserPhoneNumber == _username).FirstOrDefault(); } if (LoginCredential == null) { return(Content(HttpStatusCode.Unauthorized, new { code = ErrorCode.INVALID_CREDENTIALS })); } return(Ok(AutoMapper.Mapper.Map <LoginCredentialDTO>(LoginCredential))); }
public IHttpActionResult ForgetPassword([FromBody] LoginCredentialLoginForm request) { var _loginType = request._loginType; string _username = request._username; LoginCredential LoginCredential = null; if (_loginType == "Email") { LoginCredential = _context.LoginCredentials. Where(x => x.User.UserEmail == _username).FirstOrDefault(); if (LoginCredential == null) { return(Content(HttpStatusCode.Unauthorized, new { code = ErrorCode.INVALID_EMAIL_FOR_FORGET_PASSWORD })); } } else if (_loginType == "PhoneNumber") { LoginCredential = _context.LoginCredentials. Where(x => x.User.UserPhoneNumber == _username).FirstOrDefault(); if (LoginCredential == null) { return(Content(HttpStatusCode.Unauthorized, new { code = ErrorCode.INVALID_PHONE_NUMBER_FOR_FORGET_PASSWORD })); } LoginCredential.Password = RandomString(8); _context.Entry(LoginCredential).State = System.Data.Entity.EntityState.Modified; _context.SaveChanges(); NotificationsController NotiCtrl = new NotificationsController(); NotiCtrl.sendTextMessage(LoginCredential.User.UserPhoneNumber, "Your new password is " + LoginCredential.Password); return(Ok("SMS Sent to " + LoginCredential.User.UserPhoneNumber)); } throw new NotSupportedException(); }