public JObject ForgetPasswordSendOTP() { try { var userName = _httpContextProxy.GetQueryString("user_name"); if (userName == null) { return(_responseBuilder.BadRequest()); } var user = _znxtUserService.GetUserByUsername(userName); if (user != null) { if (_userNotifierService.SendForgetpasswordEmailWithOTPAsync(user).GetAwaiter().GetResult()) { return(_responseBuilder.Success()); } else { _logger.Error("Error on SendForgetpasswordEmailWithOTPAsync"); return(_responseBuilder.ServerError()); } } else { _logger.Error($"No user found for user_name : {userName}"); return(_responseBuilder.NotFound()); } } catch (Exception ex) { _logger.Error(ex.Message, ex); return(_responseBuilder.ServerError()); } }
public JObject IsOTPLoginRequired() { try { var user_name = _httpContextProxy.GetQueryString("user_name"); if (!string.IsNullOrEmpty(user_name)) { var data = _ZNxtUserService.GetUserByUsername(user_name); if (data != null) { if (data.roles.Where(f => f == "init_login_email_otp").Any()) { return(_responseBuilder.Success()); } else { return(_responseBuilder.BadRequest()); } } else { return(_responseBuilder.BadRequest()); } } else { return(_responseBuilder.BadRequest()); } } catch (Exception ex) { _logger.Error(ex.Message, ex); return(_responseBuilder.ServerError()); } }
// // Summary: // Finds the user by username. // // Parameters: // username: // The username. public UserModel FindByUsername(string username) { return(_userService.GetUserByUsername(username)); }
public JObject AdminAddUser() { try { var request = _httpContextProxy.GetRequestBody <AdminAddUserModel>(); _logger.Debug("Validation model"); var results = new Dictionary <string, string>(); if (request.IsValidModel(out results)) { _logger.Debug("Getting user service"); _logger.Debug("Calling GetUserByEmail"); if (_ZNxtUserService.GetUserByUsername(request.user_name) == null) { var userModel = new UserModel() { email = request.email, user_id = long.Parse($"{CommonUtility.GetUnixTimestamp(DateTime.UtcNow)}{CommonUtility.RandomNumber(4)}").ToString(), user_name = request.user_name, first_name = request.first_name, middle_name = request.middle_name, last_name = request.last_name, salt = CommonUtility.GetNewID(), is_enabled = true, user_type = "user_pass", //dob = request.dob, id = CommonUtility.GetNewID(), roles = new List <string> { "init_login_email_otp" } }; _logger.Debug("Calling CreateUser"); var response = _ZNxtUserService.CreateUser(userModel, false); if (response) { JObject userInfo = new JObject(); userInfo["mobile_number"] = request.mobile_number; userInfo["whatsapp_mobile_number"] = request.whatsapp_mobile_number; userInfo["gender"] = request.gender; if (_ZNxtUserService.UpdateUserProfile(userModel.user_id, userInfo)) { _userNotifierService.SendWelcomeEmailWithOTPLoginAsync(userModel).GetAwaiter().GetResult(); var resonseData = new JObject() { [CommonConst.CommonField.USER_ID] = userModel.user_id }; return(_responseBuilder.Success(resonseData)); } else { _logger.Error($"Error while updating user profile {userModel.user_id}", null, userInfo); return(_responseBuilder.ServerError()); } } else { return(_responseBuilder.ServerError()); } } else { JObject errors = new JObject(); errors["error"] = $"User id already registered : {request.user_name}"; return(_responseBuilder.BadRequest(errors)); } } else { _logger.Debug("Model validation fail"); JObject errors = new JObject(); foreach (var error in results) { errors[error.Key] = error.Value; } return(_responseBuilder.BadRequest(errors)); } } catch (Exception ex) { _logger.Error(ex.Message, ex); return(_responseBuilder.ServerError()); } }