Example #1
0
 public override string[] GetRolesForUser(string username)
 {
     var efUnitOfWork = new EFUnitOfWork();
     var adminRepos = new administratorsRepository(new EFRepository<administrators>(), efUnitOfWork);
     var adminUser = adminRepos.GetByUsername(username);
     if (adminUser != null)
     {
         return new string[] { CustomRoles.Admin.ToString() };
     }else
     {
         var lecurerRepos = new lecturersRepository(new EFRepository<lecturers>(), efUnitOfWork);
         var lecturerUser =  lecurerRepos.GetByUsername(username);
         if(lecturerUser!=null)
         {
             return new string[] { CustomRoles.Lecturer.ToString() };
         }
     }
     return new string[] { CustomRoles.Student.ToString() };
 }
Example #2
0
        public ActionResult LogOn(LogOnModel model, FormCollection collection, string returnUrl)
        {
            var userType = 0;
            var eventKey = "";
            var nickName = "";
            int.TryParse(collection["userType"], out userType);

            if (userType == 0)
            {
                ModelState.AddModelError("Usertype", "Please select type");
                return View();
            }
            var userFound = false;
            if (ModelState.IsValid)
            {

                var efUnitOfWork = new EFUnitOfWork();
                switch (userType)
                {
                    case 1:
                        var adminRepos = new administratorsRepository(new EFRepository<administrators>(), efUnitOfWork);
                        var _admin = adminRepos.GetByUsername(model.UserName, model.Password);
                        userFound = _admin != null;
                        break;
                    case 2:
                        var lecturerRepos = new lecturersRepository(new EFRepository<lecturers>(), efUnitOfWork);
                        var _lecturerUser = lecturerRepos.GetByUsername(model.UserName, model.Password);
                        userFound = _lecturerUser != null;
                        break;
                    case 3:
                        eventKey = collection["EventKey"];
                        nickName = collection["nickname"];
                        return RedirectToAction("Questions", "Student", new { nickname = nickName, eventkey = eventKey });
                }

                if (userFound)
                {
                    FormsService.SignIn(model.UserName, model.RememberMe);
                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "Home");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }