Exemplo n.º 1
0
        public ActionResult ResetPasswordVerified(int id, string password, string rePassword)
        {
            var user = _db.UserSet.First(u => u.Id == id);

            if (password.Length < 4 || password != rePassword)
            {
                ViewBag.Error = "Lösenord är mindre än mindre än 4 tecken. Eller fälterna matchar inte. Prova igen.";
                return(ResetPasswordVerified(user.Id, user.Token));
            }

            try
            {
                user.Password = password;
                user.Token    = "";
                _db.SaveChanges();

                var userData = AdminAuthenticationHelper.GetUserData(user);
                AdminAuthenticationHelper.Current.Login(userData);

                ViewBag.Message = "Nytt lösenord registrerat.";
                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception e)
            {
                ViewBag.Error = "Det gick inte att återställa lösenordet. Prova igen eller kontakta administratör.";
                ViewBag.Error = $"{e.Message}. {e.InnerException?.Message}";
                return(ResetPasswordVerified(user.Id, user.Token));
            }
        }
Exemplo n.º 2
0
        // GET: Users/Details/5
        public ActionResult Login(string username, string password)
        {
            var list = _db.UserSet.Where(u => u.Username == username && u.Password == password && u.Active);

            if (!list.Any())
            {
                TempData["error"] = "Wrong username or password";
                return(RedirectToAction("Index", "Home"));
            }
            var userData = AdminAuthenticationHelper.GetUserData(list.First());

            AdminAuthenticationHelper.Current.Login(userData);
            if (userData.Role == Role.xlutz.ToString())
            {
                return(RedirectToAction("Index", "Home"));
            }
            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Include = "Id,Name,Lastname,PersonalNbr,Username,EmployeeNbr,Email,Password,Role,Token")] User user)
        {
            if (!ModelState.IsValid)
            {
                return(View("Create"));
            }

            if (_db.UserSet.Any(u => u.Username == user.Username || u.Email == user.Email))
            {
                ViewBag.Error = "Användarenamn eller epos redan registrerad.";
                return(View("Create"));
            }

            if (user.Token == "xxxlutz@3399" || user.Token == "qt@5252")
            {
                //user.Role = user.Token == "xxxlutz@3399" ? Role.xlutz.ToString() : Role.qt.ToString();

                user.Order  = (short)(_db.UserSet.Count(u => u.Role == user.Role) + 1);
                user.Active = true;
                _db.UserSet.Add(user);
                try
                {
                    _db.SaveChanges();
                    var userData = AdminAuthenticationHelper.GetUserData(user);
                    AdminAuthenticationHelper.Current.Login(userData);
                    return(RedirectToAction("Index", "Home"));
                }
                catch (Exception e)
                {
                    ViewBag.Error = e.Message + "<br/>" + e.InnerException?.Message + "</br>";
                }
            }
            ViewBag.Error += "Unvalid Administrator password.";

            return(View("Create"));
        }