Ejemplo n.º 1
0
        ///<summary>
        ///Default post handler:
        ///Checks the validity of the request inputs,
        ///creates cookie for the current user and
        ///redirects accordingly
        ///</summary>
        public void OnPost(string inputUsername, string inputPassword)
        {
            if (inputUsername is null || inputPassword is null)
            {
                State = "Please enter your info";
                return;
            }
            while (inputUsername.Length < 6)
            {
                inputUsername = "******" + inputUsername;
            }
            if (inputUsername.Length == 6)
            {
                inputUsername = "******" + inputUsername;
            }
            string             AuthStr;
            User               user;
            AdminAuthorization auth;

            try
            {
                string encPw = Crypt.Encrypt(inputPassword);
                user = (User)_context.UserSet.Single(b => (b.Username == inputUsername) && (b.Password == encPw));
            }
            catch (Exception)
            {
                State = "Login failed.";
                return;
            }
            try
            {
                auth = (AdminAuthorization)_context.AdminAuthorizationSet.Single(b => (b.UserId == user.Id));
            }
            catch (Exception)
            {
                State = "Login failed.";
                return;
            }
            State   = "login success";
            AuthStr = (auth.Customize ? 1 : 0) + "" + (auth.Requests ? 1 : 0) + "" + (auth.Authority ? 1 : 0);
            Interconnector.CreateCookie(user, AuthStr, HttpContext, "EN");
            if (user.Role == 1)
            {
                Response.Redirect("/admin", false);
            }
            if (user.Role == 2)
            {
                Response.Redirect("/worked", false);
            }
            else
            {
                State = "Your account is inactive";
            }
        }
Ejemplo n.º 2
0
        ///<summary>
        ///Handles the Logout and Language change requests.
        /// creates a new cookie with desired language or
        /// logs out the user and redirects to login page
        ///</summary>
        public async Task OnPostLogoutAsync()
        {
            string Button = HttpContext.Request.Form["button"];

            if (!Button.Contains("Logout"))
            {
                Interconnector.CreateCookie(User, HttpContext, Button);
                Response.Redirect("/admin", false);
                return;
            }
            await HttpContext.SignOutAsync(
                CookieAuthenticationDefaults.AuthenticationScheme);

            Response.Redirect("/login", false);
        }