Пример #1
0
        public IActionResult SignIn(string id, string password)
        {
            UserManagementModel userManagementModel
                = new UserManagementModel(configuration);
            string result = "";
            int    res    = userManagementModel.SignIn(id, password, ref result);

            ViewData["Result"] = result;

            if (res == 0)
            {
                Microsoft.AspNetCore.Http.CookieOptions cookieOptions
                    = new Microsoft.AspNetCore.Http.CookieOptions()
                    {
                    Path        = "/",
                    HttpOnly    = true,
                    IsEssential = true,
                    Expires     = DateTime.Now.AddHours(1),
                    };

                Response.Cookies.Append("ID"
                                        , Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(id))
                                        , cookieOptions);

                return(RedirectToAction("Home", "Home"));
            }
            else
            {
                return(RedirectToAction("Entrance", "Main"));
            }
        }
Пример #2
0
        protected bool CheckSigned(ref string message)
        {
            UserManagementModel model = new UserManagementModel(configuration);

            string idBase64 = Request.Cookies["ID"];

            if (!string.IsNullOrEmpty(idBase64))
            {
                string id = System.Text.Encoding.Default.GetString(Convert.FromBase64CharArray(
                                                                       idBase64.ToCharArray(), 0, idBase64.Length));

                if (!string.IsNullOrEmpty(id))
                {
                    int result = model.SignIn(id, "", ref message);
                    return(result == 1 ? false : true);
                }
            }

            return(false);
        }