public async Task <IActionResult> SendVerificationCode([FromBody] User_Verify_BindingModel collection) { if (string.IsNullOrWhiteSpace(collection.DeviceId)) { return(BadRequest(_stringLocalizer[SharedResource.DeviceIdNotFound])); } try { var model = _mapper.Map <User_SetVerificationCode_Schema>(collection); model.VerificationCode = _randomGenerator.Create("****"); await _userService.SetVerificationCodeAsync(model); switch (model.StatusCode) { case 400: return(BadRequest(_stringLocalizer[SharedResource.DeviceIdNotFound])); case 410: return(BadRequest(_stringLocalizer[SharedResource.UserIsNotActive])); case 416: return(BadRequest(_stringLocalizer["u must register a cell phone first"])); case 417: return(BadRequest(_stringLocalizer["CellPhone does not match"])); case 418: return(BadRequest(_stringLocalizer["u must register an email first"])); case 419: return(BadRequest(_stringLocalizer["Email does not match"])); case 200: { if (!string.IsNullOrWhiteSpace(model.CellPhone)) { // Send SMS _smsService.Send(model.CellPhone, $"{_stringLocalizer["This is your verification code"]} {model.VerificationCode}"); } if (!string.IsNullOrWhiteSpace(model.Email)) { // Send Email _emailService.Send(model.CellPhone, _stringLocalizer["VerificationCode"], $"{_stringLocalizer["This is your verification code"]} {model.VerificationCode}"); } return(Ok()); } } } catch (Exception ex) { Log.Error(ex, MethodBase.GetCurrentMethod().Name); await _exceptionService.InsertAsync(ex, URL, IP); } return(InternalServerError()); }
public async Task <IActionResult> Verify([FromBody] User_Verify_BindingModel collection) { HeaderValidator(collection); try { var model = _mapper.Map <User_Verify_Schema>(collection); await _userService.VerifyAsync(model); switch (model.StatusCode) { case 400: return(BadRequest(_stringLocalizer[SharedResource.AuthenticationFailed])); case 405: return(BadRequest(_stringLocalizer[SharedResource.DeviceIsNotActive])); case 410: return(BadRequest(_stringLocalizer[SharedResource.UserIsNotActive])); case 416: return(BadRequest(_stringLocalizer["u must register a cell phone first"])); case 417: return(BadRequest(_stringLocalizer["CellPhone does not match"])); case 418: return(BadRequest(_stringLocalizer["u must register an email first"])); case 419: return(BadRequest(_stringLocalizer["Email does not match"])); case 205: return(Ok(_stringLocalizer["u'r cell phone is already active"])); case 210: return(Ok(_stringLocalizer["u'r email is already active"])); case 200: return(Ok()); } } catch (Exception ex) { Log.Error(ex, MethodBase.GetCurrentMethod().Name); await _exceptionService.InsertAsync(ex, URL, IP); } return(InternalServerError()); }