public Object AddUser(User u) { int result = 0; string errorMessage = ""; //TODO: better validation if (u.UserName.Length >= 2 && u.UserPassword.Length >= 8 && u.DisplayName.Length >= 2) { User isDuplicate = userData.GetUserByUserName(u.UserName); if (isDuplicate is null) { result = userData.AddUser(u); } else { errorMessage = "User already exists"; } } else { errorMessage = "Invalid user format"; } u.UserPassword = "******"; return(new { success = result == 1 ? true : false, errorMessage, user = u }); }
public UserDto Add(UserDto user) { _userData.AddUser(user); _userList = _userData.GetAllUsers(); user.Id = _userList.Last().Id; return(user); }
public void AddUserToDatabase_AddUser_SeeIfUserIsCreated() { // Arrange UserDto user = new UserDto(); user.Username = "******"; user.Email = "*****@*****.**"; user.Password = "******"; // Act _userData.AddUser(user); _userList = _userData.GetAllUsers(); // Assert Assert.IsTrue(_userList.Last().Username == "Test" && _userList.Last().Email == "*****@*****.**"); _userData.RemoveUser(_userList.Last().Id); }
public IActionResult AddUser(User user) { if (_userData.ValidateUserData(user)) { _userData.AddUser(user); return(Created(HttpContext.Request.Scheme + "://" + HttpContext.Request.Host + HttpContext.Request.Path + "/" + user.UserId , user)); } return(BadRequest("Incorrect user data!")); }
public async Task<ulong> AddUser(User user) { var usernameExists = await CheckIfUsernameExists(user.UserName); if(!usernameExists) { var userId = await _userData.AddUser(user, _connectionService.GetConnection(0)); return userId; } else { return 0; } }
public ActionResult Create(User user) { ViewBag.Title = CreateTitle; ViewBag.SubmitText = CreateButton; //if (string.IsNullOrEmpty(user.Name)) //{ // ModelState.AddModelError(nameof(user.Name), "The name is required"); // html hoppers handle the error display that we feed here //} if (ModelState.IsValid) { db.AddUser(user); TempData["Message"] = "User was added successfully"; return(RedirectToAction("Details", new { id = user.Id })); } return(View("CreateAndEdit")); }
public IActionResult OnPost() { if (!ModelState.IsValid) { return(Page()); } if (Account.Id > 0) { //Do something } else { Account.Password = Hashit(); Account.Role = "Admin"; _userData.AddUser(Account); } _userData.Commit(); return(RedirectToPage("/CMS/Settings/User/UserList")); }
public async Task <ActionResult <User> > Add([FromBody] User user) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { Console.WriteLine(user.Username); await userData.AddUser(user); return(Created($"/{user.Username}", user)); } catch (Exception e) { Console.WriteLine(e); return(StatusCode(500, e.Message)); } }
public JsonResult AddUser([FromBody] User user) { try { var validator = new UserValidator(); var results = validator.Validate(user); if (results.IsValid) { return(Json(new { status = "Success", message = _userInformation.AddUser(user) })); } else { var error = results.Errors.Aggregate("", (current, failure) => current + failure.ErrorMessage); throw new Exception(error); } } catch (Exception ex) { return(Json(new { status = "error", message = ex.Message })); } }
public IActionResult AddUser(AddUser model) { var newUser = new AddUser(); newUser.FirstName = model.FirstName; newUser.LastName = model.LastName; newUser.LoginName = model.LoginName; newUser.Dollors = model.Dollors; bool success = _userData.AddUser(newUser); if (success) { ViewBag.Message = "User Added!"; return(View()); } else { ViewBag.Message = "Error in adding user"; return(View()); } }
public User processStart() { const string info = "Программа калькулятор:" + "\nВыберите нужный пункт меню:\n 1. Регистрация нового пользователя" + " \n 2. Войти в систему под пользователем" + " \n 3. Удалить аккаунт \n4. Изменить пароль пользователя"; //\n 3. Исправить данные пользователя \n 4. Удалить пользователя \n 5.Выход из программы"; int operation; Console.WriteLine(info); do { Console.Write("Введите номер операции:"); if (int.TryParse(Console.ReadLine(), out operation)) { if (operation >= 1 && operation <= 4) { break; } else { Console.WriteLine("Не корректные данные"); } } } while (true); switch (operation) { case 1: { this.user = InputeDataUser(); if (!users.AddUser(user)) { user = null; } break; } case 2: { user = InputeDataUser(); if (!user.Equals(users.GetUser(user.Name))) { Console.WriteLine("Неверное имя пользователя или пароль!"); user = null; } break; } case 3: { user = InputeDataUser(); if (user.Equals(users.GetUser(user.Name))) { users.DeleteUser(user); } else { Console.WriteLine("Такого юзера нет!"); } user = null; break; } case 4: { user = InputeDataUser(); if (user.Equals(users.GetUser(user.Name))) { bool validation_flag = false; string password; do { Console.WriteLine("Введите новый пароль:"); password = Console.ReadLine(); if (!ValidationData.isCorrectStringData(password, 3)) { Console.WriteLine("Пароль должен быть не менее 3 символов"); } else { validation_flag = true; } } while (!validation_flag); users.EditUSer(user, password); } else { user = null; Console.WriteLine("Такого юзера нет!"); } break; } } return(user); }
public bool AddUser(User user) { user.Password = Codification.EncodePasswordToBase64(user.Password); user.Tipo = 1; return(_dataUser.AddUser(user)); }
public IActionResult AddUser(User user) { _userData.AddUser(user); return(Created(HttpContext.Request.Scheme + "://" + HttpContext.Request.Host + HttpContext.Request.Path + user.Id, user)); }
public ActionResult Register(User user) { db.AddUser(user); return(View()); }
public void AddUser(User user) { _userData.AddUser(user); }