Beispiel #1
0
 public static bool AdminRole(string user)
 {
     HOTP_Entities db = new HOTP_Entities();
     bool adminUser = false;
     try
     {
         adminUser = (from e in db.tblHOTP_Employees
                       where e.Email == user
                       select e.Admin).First();
     }
     catch { }
     //            orderby g.PillarGoalName
     //            select g;
     return adminUser;
 }
Beispiel #2
0
 public static string GetWeight(int employeeID, int goalID)
 {
     HOTP_Entities db = new HOTP_Entities();
     string currWeight = "";
     try
     {
        int weight = (from eg in db.tblHOTP_EmployeeGoals
                       where eg.EmployeeID == employeeID && eg.GoalID == goalID
                       select eg.Weight).First();
        currWeight = weight.ToString();
     }
     catch {}
     //            orderby g.PillarGoalName
     //            select g;
     return currWeight.ToString();
 }
Beispiel #3
0
        public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            // Require the user to have a confirmed email before they can log on.
            var user = await UserManager.FindByNameAsync(model.Email);
            if (user != null)
            {
                if (!await UserManager.IsEmailConfirmedAsync(user.Id))
                {
                    ViewBag.errorMessage = "You must have a confirmed email to log on.";
                    return View("Error");
                }
            }

            if(await UserManager.CheckPasswordAsync(user, model.Password))
            {
                // Require user to be set up in employee table.
                HOTP_Entities db = new HOTP_Entities();
                tblHOTP_Employees tblHOTP_Employees = db.tblHOTP_Employees.Where(e => e.Email == model.Email).SingleOrDefault();
                if (tblHOTP_Employees == null)
                {
                    ViewBag.errorMessage = "Not a valid user in this system.";
                    return View("Error");
                }

                // Require user to be active
                if (tblHOTP_Employees.EmpStatus != "Active")
                {
                    ViewBag.errorMessage = "Inactive employee.";
                    return View("Error");
                }

            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
            switch (result)
            {
                case SignInStatus.Success:
                    {
                        HOTP_Entities db = new HOTP_Entities();
                        tblHOTP_Employees tblHOTP_Employees = db.tblHOTP_Employees.Where(e => e.Email == model.Email).Single();
                        //if (tblHOTP_Employees.Admin) user.AdminUser = "******";
                        //else user.AdminUser = "******";
                        SetCookie(tblHOTP_Employees);
                        return RedirectToLocal(returnUrl);
                    }
                case SignInStatus.LockedOut:
                    return View("Lockout");
                case SignInStatus.RequiresVerification:
                    return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
                case SignInStatus.Failure:
                default:
                    ModelState.AddModelError("", "Invalid login attempt.");
                    return View(model);
            }
        }