public async Task <ActionResult> DoLogin(UserViewModel uvm) { if (ModelState.IsValid) { userinfo user = new userinfo(); user.username = uvm.username; user.password = UserBusinessLayer.GetMD5(uvm.password); UserBusinessLayer ubl = new UserBusinessLayer(); switch (await ubl.loginAsync(user)) { case "admin": return(RedirectToAction("Index", "DB")); case "user": SignInAsync(user); return(RedirectToAction("Index", "Home")); case "NoUser": ViewBag.errorMsg = "用户名不存在或密码错误"; return(View("Login", uvm)); } return(new EmptyResult()); } else { return(View("Login", uvm)); } }
public async Task <ActionResult> AddUser(UserViewModel uvm) { if (ModelState.IsValid) { userinfo user = new userinfo(); user.username = uvm.username; user.password = UserBusinessLayer.GetMD5(uvm.password); user.rights = "user"; UserBusinessLayer ubl = new UserBusinessLayer(); if (await ubl.Add(user)) { return(RedirectToAction("Login")); } else { ViewBag.errorMsg = "用户名已存在"; return(View("Register")); } } else { return(View("Register", uvm)); } }