예제 #1
0
        //Lấy thông tin xác thực từ request
        public static SSOHttpRequestParams GetRequestParams(HttpRequest Request)
        {
            SSOHttpRequestParams par     = new SSOHttpRequestParams();
            HttpCookie           aCookie = null;

            try
            {
                par.Action    = Request.Params[SSOConstants.UrlParams.ACTION];
                par.ReturnUrl = Request.Params[SSOConstants.UrlParams.RETURN_URL];
                //par.Token = Request.Params[SSOConstants.UrlParams.TOKEN];

                aCookie = Request.Cookies[SSOConstants.Cookie.AUTH_COOKIE];
                if (aCookie != null)
                {
                    string          encrString = aCookie.Value;
                    string          decString  = Utility.Decrypt(encrString, true, Config.SECURITY_KEY);
                    SSOCookieValues cv         = JsonConvert.DeserializeObject <SSOCookieValues>(decString);
                    par.Token = cv.Token;
                }
            }
            catch (Exception ex)
            {
                Utility.WriteToLogFile(DateTime.Now.ToString("dd/MM/yyyy") + ": " + JsonConvert.SerializeObject(aCookie));
                Utility.WriteToLogFile(DateTime.Now.ToString("dd/MM/yyyy") + ": " + ex.ToString());
                par = null;
            }

            return(par);
        }
예제 #2
0
        public static SSOHttpRequestParams GetRequestParams(HttpRequestBase Request)
        {
            SSOHttpRequestParams par = new SSOHttpRequestParams();

            par.Action    = Request.Params[SSOConstants.UrlParams.ACTION];
            par.ReturnUrl = Request.Params[SSOConstants.UrlParams.RETURN_URL];
            par.Token     = Request.Params[SSOConstants.UrlParams.TOKEN];

            if (par.Token == null)
            {
                HttpCookie aCookie = Request.Cookies[SSOConstants.Cookie.AUTH_COOKIE];
                if (aCookie != null)
                {
                    string          encrString = aCookie.Value;
                    string          decString  = Utility.Decrypt(encrString, true, Config.SECURITY_KEY);
                    SSOCookieValues cv         = JsonConvert.DeserializeObject <SSOCookieValues>(decString);
                    par.Token = cv.Token;
                }
            }

            return(par);
        }
예제 #3
0
        /// <summary>
        /// Authenticates user from the system
        /// </summary>
        /// <param name="UserName"></param>
        /// <param name="Password"></param>
        /// <returns>UserLoginInfors if authenticate success, if not success, return null</returns>
        public static SSOUserLoginInfors AuthenticateUser(string UserName, string Password, ref string thongBao)
        {
            SSOUserLoginInfors Us   = null;
            HT_NGUOIDUNG       user = null;

            thongBao = "";
            if (UserName != null && UserName != "")
            {
                using (MPLISEntities db = new MPLISEntities())
                {
                    user = db.HT_NGUOIDUNG.Where(c => c.TENDANGNHAP.ToUpper().Equals(UserName.ToUpper()) && c.MATKHAU.Equals(Password)).FirstOrDefault();
                    if (user == null)
                    {
                        thongBao = "Người dùng hoặc mật khẩu không đúng";
                    }
                    else
                    {
                        if (user.CHOPHEPSUDUNG == "1")
                        {
                            if (user.THOIDIEMMATKHAUCOHIEULUC != null && user.THOIDIEMMATKHAUHETHIEULUC != null)
                            {
                                // Xac dinh khoang thoi gian ma Nguoi dung duoc phep truy cap he thong
                                //var nguoiDung = db.HT_NGUOIDUNG.Where(p => p.NGUOIDUNGID == user.NGUOIDUNGID).FirstOrDefault();
                                if (user.THOIDIEMMATKHAUCOHIEULUC != null && user.THOIDIEMMATKHAUHETHIEULUC != null)
                                {
                                    if (DateTime.Compare(DateTime.Parse(DateTime.Now.ToString()), DateTime.Parse(user.THOIDIEMMATKHAUCOHIEULUC.ToString())) >= 0)
                                    {
                                        if (DateTime.Compare(DateTime.Parse(DateTime.Now.ToString()), DateTime.Parse(user.THOIDIEMMATKHAUHETHIEULUC.ToString())) > 0)
                                        {
                                            thongBao = "Tài khoản đã hêt hạn tham gia hệ thống";
                                            user     = null;
                                        }
                                    }
                                    else
                                    {
                                        thongBao = "Tài khoản chưa đến thời điểm tham gia hệ thống";
                                        user     = null;
                                    }
                                }
                                else
                                {
                                    thongBao = "Tài khoản chưa xác định được thời gian tham gia hệ thống";
                                    user     = null;
                                }
                            }
                        }
                        else
                        {
                            thongBao = "Tài khoản đã bị khóa";
                            user     = null;
                        }
                    }
                }
            }

            if (user != null) //xác thực thành công, thêm thông tin xác thực người dùng vào danh sách người dùng đã xác thực để quản lý
            {
                Us = GetUserInfor(user);
                HttpCookie      aCookie = new HttpCookie(SSOConstants.Cookie.AUTH_COOKIE);//("VILISUserLoginInfo");
                SSOCookieValues cv      = new SSOCookieValues();
                cv.UserName  = user.TENDANGNHAP;
                cv.Token     = Us.Token;
                cv.LastVisit = DateTime.Now;
                string retString  = JsonConvert.SerializeObject(cv);
                string encrString = Utility.Encrypt(retString, true, Config.SECURITY_KEY);
                aCookie.Value   = encrString;
                aCookie.Expires = DateTime.Now.AddMinutes(Config.AUTH_COOKIE_TIMEOUT_IN_MINUTES);
                Us.UserCookie   = aCookie;

                CheckAccountLoginAndAdd(Us);
            }

            return(Us);
        }