コード例 #1
0
 public override string[] GetRolesForUser(string username)
 {
     AppIdentityDBContext db = new AppIdentityDBContext();
     string s = db.Users.Where(x => x.Username == username).FirstOrDefault().Role;
     string[] resultS = { s };
     return resultS;
 }
コード例 #2
0
        public ActionResult Login(User u)
        {
            AppIdentityDBContext db = new AppIdentityDBContext();
            var count = db.Users.Where(x => x.Username == u.Username && x.Password == u.Password).Count();
            var checkuser = db.Users.Where(x => x.Username == u.Username && x.Password == u.Password && x.Role=="p").Count();
            if (count == 0)
            {
                ViewBag.Msg = "Invalid User!";
                return View();
            }

            else if (checkuser != 0)
            {
                ViewBag.Mssg = "Your account is waiting for approval!";
                return View();
            }

            else
            {
                FormsAuthentication.SetAuthCookie(u.Username, false);
                return RedirectToAction("Index", "Home");
            }
        }
コード例 #3
0
 public ActionResult Register(User u)
 {
     if (ModelState.IsValid)
     {
         var checkUser = db.Users.Where(x => x.Username == u.Username).Count();
         if (checkUser == 0)
         {
             using (AppIdentityDBContext db = new AppIdentityDBContext())
             {
                 u.Role = "p";
                 u.Approved = "pending";
                 db.Users.Add(u);
                 db.SaveChanges();
                 ModelState.Clear();
                 u = null;
                 ViewBag.Msg = "Successfully registered.";
             }
         }
         else
         {
             ViewBag.Msg = "That username is already taken, try another one.";
             return View(u);
         }
     }
     return View(u);
 }