public ActionResult Index(string EmailID)
        {
            //Verify Email ID
            //Generate Reset password link
            //Send Email
            string message = "";
            bool   status  = false;

            using (LibraryOnlineFinalEntities db = new LibraryOnlineFinalEntities())
            {
                var account = db.Users.Where(a => a.username == EmailID).FirstOrDefault();
                if (account != null)
                {
                    //Send email for reset password
                    string resetCode = Guid.NewGuid().ToString();
                    SendVerificationLinkEmail(account.username, resetCode, "ResetPassword");
                    account.resetPasswordCode = resetCode;
                    //This line I have added here to avoid confirm password not match issue , as we had added a confirm password property
                    //in our model class in part 1
                    db.Configuration.ValidateOnSaveEnabled = false;
                    db.SaveChanges();
                    message = "Link lấy lại mật khẩu đã được gửi vào email của bạn!";
                }
                else
                {
                    message = "Tài khoản không tìm thấy!";
                }
            }
            ViewBag.Message = message;
            return(View());
        }
        public ActionResult ResetPassword(ResetPasswordModel model)
        {
            var message = "";

            if (ModelState.IsValid)
            {
                using (LibraryOnlineFinalEntities db = new LibraryOnlineFinalEntities())
                {
                    var user = db.Users.Where(a => a.resetPasswordCode == model.ResetCode).FirstOrDefault();
                    if (user != null)
                    {
                        //user.Password = Crypto.Hash(model.NewPassword);
                        //user.password = md5(model.NewPassword);
                        user.password          = Encrypt(model.NewPassword);
                        user.resetPasswordCode = "";
                        db.Configuration.ValidateOnSaveEnabled = false;
                        db.SaveChanges();
                        message = "Cập nhật mật khẩu mới thành công!";
                    }
                }
            }
            else
            {
                message = "Bạn phải nhật mật khẩu và xác nhận lại mật khẩu!";
            }
            ViewBag.Message = message;
            return(View(model));
        }
        public ActionResult ResetPassword(string id)
        {
            //Verify the reset password link
            //Find account associated with this link
            //redirect to reset password page
            if (string.IsNullOrWhiteSpace(id))
            {
                return(HttpNotFound());
            }

            using (LibraryOnlineFinalEntities db = new LibraryOnlineFinalEntities())
            {
                var user = db.Users.Where(a => a.resetPasswordCode == id).FirstOrDefault();
                if (user != null)
                {
                    ResetPasswordModel model = new ResetPasswordModel();
                    model.ResetCode = id;
                    return(View(model));
                }
                else
                {
                    return(HttpNotFound());
                }
            }
        }
 public string Login(LoginInfo loginInfo)
 {
     //loginInfo.Pass = md5(loginInfo.Pass);
     loginInfo.Pass = Encrypt(loginInfo.Pass);
     using (LibraryOnlineFinalEntities db = new LibraryOnlineFinalEntities())
     {
         var user = db.Users.Where(x => x.username == loginInfo.User && x.password == loginInfo.Pass)
                    .FirstOrDefault();
         //var user_id = db.Users.Where(x => x.username == loginInfo.User && x.password == loginInfo.Pass).FirstOrDefault();
         if (user != null)
         {
             HttpContext.Current.Session["username"] = loginInfo.User;
             HttpContext.Current.Session["user_id"]  = user.id;
             //HttpContext.Current.Session["fullname"] = user.fullname;
             HttpContext.Current.Session["role_id"] = user.role_id;
             //HttpContext.Current.Session["image"] = user.image;
             if (user.role_id == 1 || user.role_id == 2)
             {
                 return("/Home/Index");
             }
             else if (user.role_id == 3)
             {
                 return("/Home/Student");
             }
             //var data = new {
             //    infouser = user,
             //    pass = Decrypt(user.password)
             //};
         }
     }
     return("");
 }
Esempio n. 5
0
        public string Login(LoginInfo loginInfo)
        {
            using (LibraryOnlineFinalEntities db = new LibraryOnlineFinalEntities())
            {
                var role = db.Users.Where(x => x.username == loginInfo.User && x.password == loginInfo.Pass)
                           .Select(x => x.role_id).FirstOrDefault();
                var user_id = db.Users.Where(x => x.username == loginInfo.User && x.password == loginInfo.Pass)
                              .Select(x => x.id).FirstOrDefault();
                var fullname = db.Users.Where(x => x.username == loginInfo.User && x.password == loginInfo.Pass)
                               .Select(x => x.fullname).FirstOrDefault();
                HttpContext.Current.Session["username"] = loginInfo.User;
                HttpContext.Current.Session["user_id"]  = user_id;
                HttpContext.Current.Session["fullname"] = fullname;
                if (role == 1)
                {
                    return("/Admin/Admin");
                }
                else if (role == 2)
                {
                    return("/Lecturers/Index");
                }
                else if (role == 3)
                {
                    return("/Student/Index");
                }
            }

            return("");
        }
Esempio n. 6
0
        public string UploadFiles()
        {
            var httpPostedFile = HttpContext.Current.Request.Files["fileInput"];//lấy file

            if (httpPostedFile != null)
            {
                //đường dẫn lưu file
                //string temp = RandomString(10, true) + "-";
                var fileSavePath = Path.Combine(HttpContext.Current.Server.MapPath("~/Content/Upload/"), httpPostedFile.FileName);//tên file
                //lưu file vào đường dẫn
                httpPostedFile.SaveAs(fileSavePath);
            }

            var    title        = HttpContext.Current.Request["title"];
            var    describe     = HttpContext.Current.Request["describe"];
            var    author       = HttpContext.Current.Request["author"];
            var    year         = HttpContext.Current.Request["year"];
            var    userid       = HttpContext.Current.Request["userid"];
            var    subid        = HttpContext.Current.Request["subid"];
            var    date_upload  = DateTime.Now;
            int    user_id      = Convert.ToInt32(userid);
            int    sub_id       = Convert.ToInt32(subid);
            string strExtexsion = Path.GetExtension(httpPostedFile.FileName).Trim();//lấy đuôi file
            string a            = "";

            if (strExtexsion == ".pdf")//chỉ cho up pdf
            {
                string temp = RandomString(10, true) + "-";
                using (LibraryOnlineFinalEntities db = new LibraryOnlineFinalEntities())
                {
                    //Add vô bảng ebook
                    db.Ebooks.Add(
                        new Ebook
                    {
                        ebook_id    = "",
                        title       = title,
                        describe    = describe,
                        author      = author,
                        year        = year,
                        filename    = httpPostedFile.FileName,
                        date_upload = date_upload,
                        user_id     = user_id,
                        sub_id      = sub_id,
                    });
                    db.SaveChanges();//lưu dât thôi cái này t chưa chạy t mới test gửi data từ  ajax qua thôi
                    var user     = db.Users.Where(x => x.id == user_id).Select(x => x.username).FirstOrDefault();
                    var subject  = db.Subject_Ebook.Where(x => x.id == sub_id).Select(x => x.name).FirstOrDefault();
                    var fileinfo = db.Ebooks.OrderByDescending(x => x.id).FirstOrDefault();
                    var date_up  = date_upload.ToString("MM/dd/yyyy");
                    MyHub.PostFileEbook(fileinfo.id, fileinfo.title, fileinfo.author, fileinfo.describe,
                                        fileinfo.year, fileinfo.filename, date_up, user, subject);
                    a = "Thành công";
                }
            }
            else
            {
                a = "lỗi";
            }

            return(a);
        }