public ActionResult Register(RegisterViewModel model) { if (ModelState.IsValid) { int userId = AccountBLL.Add(model.Email, model.Password); if (userId > 0) { //注册成功,用户名密码正确,构造用户数据 var userData = new HttpUserDataPrincipal { UserId = userId, UserName = model.Email }; //保存Cookie HttpFormsAuthentication <HttpUserDataPrincipal> .SetAuthCookie(model.Email, userData, false); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", "用户名已存在。"); } } return(View(model)); }
public ActionResult Register(RegisterModel model) { if (!ModelState.IsValid) { return(View(model)); } if (EmailIsExists(model.Email)) { ModelState.AddModelError("", "Email đã tồn tại!"); return(View(model)); } if (model.PassWord != model.ComfirmPass) { ModelState.AddModelError("", "Mật khẩu không khớp!"); return(View(model)); } if ((int)Session["code"] != model.codeVerify) { ModelState.AddModelError("", "Mã xác thực không đúng!"); return(View(model)); } Account acc = new Account(1, model.Email, model.UserName, model.PassWord, "user_default.png", false, true); accountBLL.Add(acc); Session.Remove("code"); return(Redirect("/Account/Login")); }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SaveButton_Click(object sender, EventArgs e) { var entity = account_Control1.AccountNumber_Entity; if (AccountBLL.RepeatVerify_Add(entity)) { if (AccountBLL.Add(entity) > -1) { DialogResult = MessageBox.Show("添加账号成功!", "账号添加提示", MessageBoxButtons.OK); //DialogResult.OK; this.Close(); } } else { MessageBox.Show(AccountBLL.Messages, "账号添加提示"); } }
private void splBtnAdd_Click(object sender, EventArgs e) { if (txtEdtUsername.Text != "" && txtEdtName.Text != "" && (rdoManager.Checked || rdoSupervisor.Checked)) { account.Username = txtEdtUsername.Text; account.Name = txtEdtName.Text; if (rdoSupervisor.Checked) { account.Role = "Giám sát"; } else { account.Role = "Quản lý"; } account.Password = txtEdtUsername.Text; dgvAdminAccount.DataSource = accountBLL.Add(account); GetAccount(); } }