private void BtnSaver_Click(object sender, EventArgs e) { if (txtUserPass.Text.Length >= 5) { if (txtUserPass.Text == txtUserCFPass.Text) { var UserSaver = new UserModel( userName: txtUserName.Text, password: txtUserPass.Text, nombre: txtFirstname.Text, apellidos: txtLastName.Text, rol: cmbRoles.SelectedItem.ToString(), email: txtUserEmail.Text); var result = UserSaver.AddUser(); MessageBox.Show(result); mostrarDatos(); inhabilitar(); } else { MessageBox.Show("The password do not match, try again"); } } else { MessageBox.Show("The password must have a minimum of 5 characters"); } }
public ActionResult AddUser(UserModel model) { // Redirect if the user isn't logged in if (!IdentityModel.CurrentUserLoggedIn) { return(RedirectToAction("Login", "Admin")); } model.AddUser(); return(View(model)); }
internal bool AddUser(string username, string password, string usertype, long phonenumber) { if (model.AddUser(username, password, usertype, phonenumber)) { return(true); } else { return(false); } }
public void form_AddUser() { var f = new FormUserAdd(); if (f.ShowDialog() == DialogResult.OK) { if (!_model.Users.Exists(x => x.Login == f.User.Login)) { _model.AddUser(f.User); _form.ShowUserList(_model.Users); } else { MessageBox.Show("Пользователь с таким логином уже существует. Добавление было прервано.", "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public ActionResult Edit(UserModel model) { if (ModelState.IsValid) { User user = UserModel.CheckForUser(model); var validateUser = PasswordHash.ValidatePassword(model.Password, user.Password); if (validateUser) { UserModel.AddUser(UserModel.ConvertToUser(model)); var model2 = UserModel.GetUserOnEmail(model.Email); SetAuthenticationCookie(model2.Password); return(View(model)); } } return(View(model)); }
public ActionResult FacebookCallback(string code, UserViewModel model) { var fb = new FacebookClient(); dynamic result = fb.Post("oauth/access_token", new { client_id = ConfigurationManager.AppSettings["FbAppId"], client_secret = ConfigurationManager.AppSettings["FbAppSecret"], redirect_uri = RedirectUri.AbsoluteUri, code = code }); var accessToken = result.access_token; if (!string.IsNullOrEmpty(accessToken)) { fb.AccessToken = accessToken; dynamic me = fb.Get("me?fields=first_name,middle_name,last_name,id,email"); string email = me.email; string userName = me.first_name + " " + me.middle_name + " " + me.last_name; string firstName = me.first_name; string middleName = me.middle_name; string lastName = me.last_name; model.Email = email; model.Name = userName; var dao = new UserModel(); var iplUser = new UserModel(); if (dao.checkInfo(model.Name, model.Email) == true) { var obUser = iplUser.AddUser(model); } var user = dao.getByUser(model.Name, model.Email); var userSession = new UserSession(); userSession.Name = user.Name; userSession.UserId = user.UserId; Session["UserId"] = user.UserId; Session.Add(SessionHelper.USER_SESSION, userSession); return(RedirectToAction("Index", "Topic")); } return(RedirectToAction("Index", "Topic")); }
public List <string> RegisterUser(string name, string password) { List <string> errors = new List <string>(); User user = new User() { Name = name, Password = password }; RegisterState state = userModel.AddUser(user); switch (state) { case RegisterState.OK: HttpContext.Current.Response.Redirect("Success.cshtml?action=register"); break; case RegisterState.Unknown: if (userModel.HasError && InDebug) { HttpContext.Current.Response.Write(userModel.GetErrorMessage()); } else { HttpContext.Current.Response.Redirect("Error.cshtml?error=500"); } break; case RegisterState.UserExists: errors.Add("An user with this name already exists."); break; } return(errors); }
public ActionResult Login(UserViewModel model) { if (ModelState.IsValid) { if (model.Name is null || model.Email is null || model.Phone is null) { ModelState.AddModelError("", "Vui lòng nhập đầy đủ thông tin"); } else { var dao = new UserModel(); if (dao.checkInfo(model.Name, model.Email) == true) { var obUser = dao.AddUser(model); } var user = dao.getByUser(model.Name, model.Email); var userSession = new UserSession(); userSession.Name = user.Name; userSession.UserId = user.UserId; Session["UserId"] = user.UserId; Session.Add(SessionHelper.USER_SESSION, userSession); return(RedirectToAction("Index", "Topic")); } }
public ActionResult Index(UserModel userModel) { try { userModel.UserTypes = new List <UserType> { new UserType { ID = "1", Type = "Internal" }, new UserType { ID = "2", Type = "External" } }; if (ModelState.IsValid) { bool isDuplicate = false; userModel.userName = userModel.userName.Trim(); isDuplicate = userModel.CheckDuplicate(userModel); if (isDuplicate) { userModel.GetUserDetails(); ViewBag.Message = "User Already Exists"; return(View("Index", userModel)); } else { userModel.AddUser(userModel); userModel.GetUserDetails(); ViewBag.Message = "New User Added Successfully"; //ViewData["Userviewmodel1"] = ""; ViewData["Userviewmodel1"] = (IEnumerable <UserModel>) from u in userModel.lstUserData join m in userModel.lstUserData on u.AuthID equals m.UserID join b in userModel.lstRoles on u.RoleID equals b.RoleID select new UserModel { userId = u.UserID, userName = u.UserName, AuthName = m.UserName, password = u.Password, CreatedDate = u.CreatedDate, Rolename = b.RoleName, Status = Convert.ToBoolean(Convert.ToInt32(u.Active)) }; return(View("Index", userModel)); } } userModel.GetUserDetails(); ViewData["Userviewmodel1"] = (IEnumerable <UserModel>) from u in userModel.lstUserData join m in userModel.lstUserData on u.AuthID equals m.UserID join b in userModel.lstRoles on u.RoleID equals b.RoleID select new UserModel { userId = u.UserID, userName = u.UserName, AuthName = m.UserName, password = u.Password, CreatedDate = u.CreatedDate, Rolename = b.RoleName, Status = Convert.ToBoolean(Convert.ToInt32(u.Active)) }; return(View(userModel)); } catch (Exception ex) { errorlogviewmodel = new ErrorLogViewModel(); errorlogviewmodel.LogError(ex); return(View("Error")); } }