Ejemplo n.º 1
0
        public IActionResult OnGet()
        {
            var usersId = HttpContext.Session.GetInt32("users_id");

            if (usersId == null)
            {
                if (HttpContext.Request.Cookies.ContainsKey("users_id"))
                {
                    usersId = int.Parse(HttpContext.Request.Cookies["users_id"]);
                    var usersName = HttpContext.Request.Cookies["users_name"];
                    HttpContext.Session.SetInt32("users_id", (int)usersId);
                    HttpContext.Session.SetString("users_name", usersName);
                }
                else
                {
                    return(Redirect("SignIn"));
                }
            }
            var usersDao = new UsersDao();

            Users   = usersDao.GetById((int)usersId);
            Courses = usersDao.GetCourses((int)usersId);
            var purchaseDao = new PurchaseDao();

            Purchases = purchaseDao.GetByUsersId((int)usersId);
            foreach (var purchase in Purchases)
            {
                purchase.CourseName = Courses.First(c => c.Id == purchase.CourseId).Name;
            }
            return(null);
        }
Ejemplo n.º 2
0
 public ActionResult Login(LoginModel model)
 {
     if (ModelState.IsValid)
     {
         var dao    = new UsersDao();
         var result = dao.Login(model.UserName, Md5Encryptor.Md5Hash(model.Password));
         if (result == 0)
         {
             var user        = dao.GetById(model.UserName);
             var userSession = new UserLogin();
             userSession.UserName = user.UserName;
             Session.Add(CommonConstants.USER_SESSION, userSession);
             return(RedirectToAction("Index", "Home"));
         }
         else if (result == 1)
         {
             ModelState.AddModelError("", "Username is not exist");
             TempData["AlertMessage"] = "Username is not exist";
             TempData["AlertType"]    = "alert-danger";
         }
         else
         {
             ModelState.AddModelError("", "Wrong Password");
             TempData["AlertMessage"] = "Wrong password";
             TempData["AlertType"]    = "alert-danger";
         }
     }
     return(View("Index"));
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 点击列表头时,数据自动填充
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dataGridView_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (this.dataGridView.Rows.Count > 0)
            {
                DataGridViewRow currentRow = this.dataGridView.Rows[e.RowIndex];
                this.userId.Text    = currentRow.Cells["UsersId"].Value.ToString();
                this.userName.Text  = currentRow.Cells["UsersName"].Value.ToString();
                this.userEmail.Text = currentRow.Cells["UsersEmail"].Value.ToString();

                user = UsersDao.GetById(this.userId.Text);

                SetPrivilege();

                if (user.UsersIsactive)
                {
                    this.delBtn.Visible      = true;
                    this.activeBtn.Visible   = false;
                    this.resetPwdBtn.Enabled = true;
                    this.saveBtn.Enabled     = true;
                }
                else
                {
                    this.delBtn.Visible      = false;
                    this.activeBtn.Visible   = true;
                    this.resetPwdBtn.Enabled = false;
                    this.saveBtn.Enabled     = false;
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 检查用户名密码,取得用户信息
        /// </summary>
        /// <returns></returns>
        private bool CheckPrivilege()
        {
            try
            {
                //取得用户信息
                if (user == null)
                {
                    user = UsersDao.GetById(this.userId.Text);
                }
            }
            catch (Exception e)
            {
                return(false);
            }

            //验证密码
            string pwd = Utilities.Md5Encrypt(this.password.Text);

            if (LoginForm.user != null)
            {
                if (!user.UsersIsactive)
                {
                    MessageBox.Show("用户已锁定,请联系管理员重新激活!");
                    return(false);
                }
                if (user.Password.Equals(Utilities.Md5Encrypt(this.password.Text)))
                {
                    LoginForm.user.LoginDate   = VehicleDao.GetCurrentDate();
                    LoginForm.user.LoginServer = server.Text;
                    return(true);
                }
                else
                {
                    MessageBox.Show("密码错误,请重试!");
                    return(false);
                }
            }
            else
            {
                MessageBox.Show("用户名不存在!");
                this.userName.Text = "";
            }
            return(false);
        }
Ejemplo n.º 5
0
        public ActionResult Index(LoginModel model)
        {
            var    dao      = new UsersDao();
            string Password = Encryptor.MD5Hash(model.Password);
            var    result   = dao.Login(model.UserName, Password);

            if (result)
            {
                var user        = dao.GetById(model.UserName);
                var userSession = new UserLogin();
                userSession.UserName = user.UserName;
                userSession.UserID   = user.UserId;
                Session.Add(CommonConstants.USER_SESSION, userSession);
                return(RedirectToAction("Index", "Index"));
            }
            else
            {
                ModelState.AddModelError("", "Đăng nhập không đúng.");
            }
            return(View());
        }
Ejemplo n.º 6
0
 private void password_Enter(object sender, EventArgs e)
 {
     if (string.IsNullOrWhiteSpace(this.userId.Text))
     {
         return;
     }
     //if (string.IsNullOrWhiteSpace(this.server.Text))
     //{
     //    return;
     //}
     user = UsersDao.GetById(this.userId.Text);
     if (user != null)
     {
         this.userName.Text = user.UsersName;
     }
     else
     {
         MessageBox.Show("用户名不存在!");
         this.userName.Text = "";
     }
 }
Ejemplo n.º 7
0
        public void OnGet()
        {
            var fileDao = new FileDao();

            AllFiles = fileDao.GetAll();
            var userDao = new UsersDao();

            foreach (var file in AllFiles)
            {
                file.UserName = userDao.GetById(file.UserId).Name;
            }
            var usersId = HttpContext.Session.GetInt32("users_id");

            if (usersId == null && HttpContext.Request.Cookies.ContainsKey("users_id"))
            {
                usersId = int.Parse(HttpContext.Request.Cookies["users_id"]);
                var usersName = HttpContext.Request.Cookies["users_name"];
                HttpContext.Session.SetInt32("users_id", (int)usersId);
                HttpContext.Session.SetString("users_name", usersName);
            }
            UserIsAuthorized = usersId != null;
        }