예제 #1
0
        public ActionResult <AuthenticateUserResponse> Login(AuthenticateUserRequest authCreds)
        {
            var response = _service.Authenticate(authCreds, ipAddress());

            setTokenCookie(response.RefreshToken);
            return(Ok(response));
        }
예제 #2
0
        public ActionResult LogOn(LogOnModel model, string returnUrl = "")
        {
            //if (ModelState.IsValid)
            //{

            //    if (Membership.ValidateUser(model.UserName, model.Password))
            //    {
            //        //FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
            //        authentication.SetAuthCookie(model.UserName, model.RememberMe);
            //        //TODO:Check if this could be made runable
            //        //if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
            //        //    && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
            //        //{
            //        //    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);
            try
            {
                if (_userAccountService.Authenticate(model.UserName, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);

                    // Will be refactored
                    Session["User"] = _userAccountService.GetUserDetail(model.UserName);
                    ////

                    // TODO: Review user permission code
                    //string[] authorization = service.GetUserPermissions(service.GetUserInfo(model.UserName).UserAccountId, "Administrator", "Manage User Account");
                    //service.GetUserPermissions(model.UserName, "CATS", "Finance");
                    return(RedirectToLocal(returnUrl));
                }
            }

            catch (Exception exception)
            {
                var log = new Logger();
                log.LogAllErrorsMesseges(exception, _log);

                ViewBag.HasError     = true;
                ViewBag.ErrorMessage = exception.ToString();

                ModelState.AddModelError("", exception.Message);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
예제 #3
0
        public IActionResult Authenticate([FromBody] UserAccountModel model)
        {
            var user = _userAccountService.Authenticate(model.Username, model.Password);

            if (user == null)
            {
                return(BadRequest(new { message = "Username or password is incorrect" }));
            }

            return(Ok(user));
        }
예제 #4
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            // Check if the supplied credentials are correct.
            try
            {
                if (service.Authenticate(model.UserName, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    // TODO: Review user permission code
                    //string[] authorization = service.GetUserPermissions(service.GetUserInfo(model.UserName).UserAccountId, "Administrator", "Manage User Account");
                    return(RedirectToLocal(returnUrl));
                }
            }

            catch (Exception exception)
            {
                ViewBag.HasError     = true;
                ViewBag.ErrorMessage = exception.ToString();
                ModelState.AddModelError("", exception.Message);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
예제 #5
0
 public bool Authenticate(string userName, string passWord)
 {
     return(_userAccountService.Authenticate(userName, passWord));
 }
예제 #6
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            // Check if the supplied credentials are correct.
            ViewBag.HasError  = false;
            ViewBag.returnUrl = returnUrl;

            // Create logger instance to record activities
            var log = new Logger();

            try
            {
                if (_userAccountService.Authenticate(model.UserName, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, true);

                    // Will be refactored
                    var user = _userAccountService.GetUserDetail(model.UserName);
                    user.LogginDate      = DateTime.Now;
                    user.NumberOfLogins += 1;
                    // Session["USER_PROFILE"] = user;
                    _userAccountService.UpdateUser(user);

                    // Add user information to session variable to avoid frequent trip to the databas
                    var service  = (IUserAccountService)DependencyResolver.Current.GetService(typeof(IUserAccountService));
                    var userInfo = service.GetUserInfo(model.UserName);
                    Session["USER_INFO"]    = userInfo;
                    Session["USER_PROFILE"] = service.GetUserDetail(model.UserName);

                    // Before trying to go and look for user permissions, check if the user is logged in or not

                    //// Load user permissions
                    IAzManStorage storage = new SqlAzManStorage(ConfigurationManager.ConnectionStrings["CatsContext"].ConnectionString);
                    IAzManDBUser  dbUser  = storage.GetDBUser(user.UserName);

                    // Early Warning user permissions
                    UserPermissionCache earlyWarningPermissionCache = new UserPermissionCache(storage, CatsGlobals.CATS, CatsGlobals.EARLY_WARNING, dbUser, true, false);
                    Session[CatsGlobals.EARLY_WARNING_PERMISSIONS] = earlyWarningPermissionCache;


                    //PSNP user permission
                    UserPermissionCache psnpPermissionCache = new UserPermissionCache(storage, CatsGlobals.CATS, CatsGlobals.PSNP, dbUser, true, false);
                    Session[CatsGlobals.PSNP_PERMISSIONS] = psnpPermissionCache;

                    // Logistics user permissions
                    UserPermissionCache logisticsPermissionCache = new UserPermissionCache(storage, CatsGlobals.CATS, CatsGlobals.LOGISTICS, dbUser, true, false);
                    Session[CatsGlobals.LOGISTICS_PERMISSIONS] = logisticsPermissionCache;

                    // Procurement user permissions
                    UserPermissionCache procurementPermissionCache = new UserPermissionCache(storage, CatsGlobals.CATS, CatsGlobals.PROCUREMENT, dbUser, true, false);
                    Session[CatsGlobals.PROCUREMENT_PERMISSIONS] = procurementPermissionCache;

                    // Hub user permissions
                    UserPermissionCache hubPermissionCache = new UserPermissionCache(storage, CatsGlobals.CATS, CatsGlobals.HUB, dbUser, true, false);
                    Session[CatsGlobals.HUB_PERMISSIONS] = hubPermissionCache;

                    // Regional user permissions
                    UserPermissionCache regionalPermissionCache = new UserPermissionCache(storage, CatsGlobals.CATS, CatsGlobals.REGION, dbUser, true, false);
                    Session[CatsGlobals.REGION_PERMISSIONS] = regionalPermissionCache;

                    // Regional user permissions
                    UserPermissionCache financePermissionCache = new UserPermissionCache(storage, CatsGlobals.CATS, CatsGlobals.FINANCE, dbUser, true, false);
                    Session[CatsGlobals.FINANCE_PERMISSIONS] = financePermissionCache;
                    // Whatever permission we are going to have!
                    _log.Info("Logged in User: "******"Administrator", "Manage User Account");
                    //service.GetUserPermissions(model.UserName, "CATS", "Finance");
                    return(RedirectToLocal(returnUrl));
                }
            }
            catch (UserNotFoundException unfe)
            {
                log.LogAllErrorsMesseges(unfe, _log);
                ViewBag.HasError     = true;
                ViewBag.Error        = unfe.ToString();
                ViewBag.ErrorMessage = "Your user name is not registered as a user on CATS. Please contact your system administrator.";
            }
            catch (DisabledUserException due)
            {
                log.LogAllErrorsMesseges(due, _log);
                ViewBag.HasError     = true;
                ViewBag.Error        = due.ToString();
                ViewBag.ErrorMessage = "Your user account is disabled. Please contact your system administrator.";
            }
            catch (UnmatchingUsernameAndPasswordException uuape)
            {
                log.LogAllErrorsMesseges(uuape, _log);
                ViewBag.HasError     = true;
                ViewBag.Error        = uuape.ToString();
                ViewBag.ErrorMessage = "The user name and password you provided do not match. Please try again with a correct combination.";
            }
            catch (Exception exception)
            {
                log.LogAllErrorsMesseges(exception, _log);

                ViewBag.HasError     = true;
                ViewBag.Error        = exception.ToString();
                ViewBag.ErrorMessage = "Login failed. Try logging in with the right user name and password.";

                ModelState.AddModelError("", exception.Message);
            }

            return(View());
        }