Пример #1
0
        public ActionResult Login(Employer model, string returnurl)
        {
            var result = new LoginMember().LoginEmployer(model.Emaildangnhap, LoginMember.MD5Hash(model.Matkhau));

            if (result == 1)
            {
                var user = db.CongTies.Where(x => x.Emaildangnhap == model.Emaildangnhap).FirstOrDefault();
                Session["Employer"] = new CongTy()
                {
                    MACT = user.MACT, Emaildangnhap = user.Emaildangnhap, Tinhtrang = user.Tinhtrang
                };
                user.matkhaureset = null;
                db.SaveChanges();
                if (returnurl == null || returnurl == "")
                {
                    return(RedirectToAction("Index", "Employer"));
                }
                else
                {
                    return(Redirect(returnurl));
                }
            }
            else if (result == 2)
            {
                ModelState.AddModelError("", "Tài khoản Chưa được Kích hoạt");
                TempData["Error"] = "Tài khoản Chưa được Kích hoạt";
                return(Redirect(Request.UrlReferrer.ToString()));
            }
            else
            {
                ModelState.AddModelError("", "Email hoặc mật khẩu không chính xác");
                TempData["Error"] = "Email hoặc mật khẩu không chính xác";
                return(Redirect(Request.UrlReferrer.ToString()));
            }
        }
        public void Uploadlogo(HttpPostedFileBase logo, int id, int mact)
        {
            var    user     = db.CongTies.Where(x => x.MACT == mact).FirstOrDefault();
            string filename = "img" + id + user.Emaildangnhap;

            filename = LoginMember.MD5Hash(filename) + logo.FileName;
            string path = System.IO.Path.Combine(Server.MapPath("~/Employer_upload/"), filename);

            logo.SaveAs(path);
        }
Пример #3
0
        public void Uploadlogo(HttpPostedFileBase logo, int id)
        {
            var    user     = Session["Employer"] as CongTy;
            string filename = "img" + id + user.Emaildangnhap;

            filename = LoginMember.MD5Hash(filename) + logo.FileName;
            string path = System.IO.Path.Combine(Server.MapPath("~/Employer_upload/"), filename);

            logo.SaveAs(path);
        }
        public ActionResult ChangePasswordAdmin(string password_first, int mauv)
        {
            var checkpassword = db.UngViens.Where(x => x.MAUV == mauv && x.vaitro == 2).FirstOrDefault();

            if (checkpassword != null)
            {
                checkpassword.Matkhau = LoginMember.MD5Hash(password_first);
                db.SaveChanges();
                return(Json(new { status = "SUCCESS" }));
            }
            else
            {
                return(Json(new { status = "ERROR_PASSWORD" }));
            }
        }
Пример #5
0
        public ActionResult ChangePasswordEmployer(string Matkhau, string Emaildangnhap)
        {
            var checkemployer = db.CongTies.Where(x => x.Emaildangnhap == Emaildangnhap).FirstOrDefault();

            if (checkemployer == null)
            {
                return(Json(0));
            }
            else
            {
                checkemployer.Matkhau      = LoginMember.MD5Hash(Matkhau);
                checkemployer.matkhaureset = null;
                db.SaveChanges();
                return(Json(1));
            }
        }
Пример #6
0
        public ActionResult ChangePassword(string password, string email)
        {
            var checkmember = db.UngViens.Where(x => x.EmailDN == email).FirstOrDefault();

            if (checkmember == null)
            {
                return(Json(0));
            }
            else
            {
                checkmember.Matkhau      = LoginMember.MD5Hash(password);
                checkmember.matkhaureset = null;
                db.SaveChanges();
                return(Json(1));
            }
        }
Пример #7
0
        public ActionResult SignUp(List <string> Manghanh, int matp, string Matkhau, string Tencongty, string Dienthoaiban, string Emaildangnhap)
        {
            Employer em = new Employer();
            CongTy   ct = new CongTy();

            foreach (var item in Manghanh)
            {
                int mn = int.Parse(item);
                if (ct.Manghanh1 == null)
                {
                    ct.Manghanh1 = mn;
                }
                else if (ct.Manghanh2 == null)
                {
                    ct.Manghanh2 = mn;
                }
                else
                {
                    ct.Manghanh3 = mn;
                }
            }
            ct.Matkhau       = LoginMember.MD5Hash(Matkhau);
            ct.MaTP1         = matp;
            ct.Dienthoaiban  = Dienthoaiban;
            ct.Tencongty     = Tencongty;
            ct.Ngaytao       = DateTime.Now;
            ct.Tinhtrang     = 0;
            ct.Emaildangnhap = Emaildangnhap;
            db.CongTies.Add(ct);
            db.SaveChanges();
            bool kq = Sendmail(Emaildangnhap);

            if (kq == true)
            {
                return(Json(1));
            }
            else if (kq == false)
            {
                db.CongTies.Remove(db.CongTies.Where(x => x.Emaildangnhap == Emaildangnhap).FirstOrDefault());
                db.SaveChanges();
                return(Json(2));
            }
            else
            {
                return(Json(2));
            }
        }
        public ActionResult ChangePassword(string password_first, int mact)
        {
            if (mact == null)
            {
                return(Json(new { status = "ERROR_PASSWORD" }));
            }
            var checkpassword = db.CongTies.Where(x => x.MACT == mact).FirstOrDefault();

            if (checkpassword != null)
            {
                checkpassword.Matkhau = LoginMember.MD5Hash(password_first);
                db.SaveChanges();
                return(Json(new { status = "SUCCESS" }));
            }
            else
            {
                return(Json(new { status = "ERROR_PASSWORD" }));
            }
        }
Пример #9
0
        public ActionResult ChangePassword(string current_password, string password_first)
        {
            var user = Session["Employer"] as CongTy;

            current_password = LoginMember.MD5Hash(current_password);
            var checkpassword = db.CongTies.Where(x => x.Matkhau == current_password && x.MACT == user.MACT).FirstOrDefault();

            if (checkpassword != null)
            {
                checkpassword.Matkhau = LoginMember.MD5Hash(password_first);
                db.SaveChanges();
                Session["Employer"] = null;
                return(Json(new { status = "SUCCESS" }));
            }
            else
            {
                return(Json(new { status = "ERROR_PASSWORD" }));
            }
        }
Пример #10
0
        public bool Sendmail(string email)
        {
            var checkemployer = db.CongTies.Where(x => x.Emaildangnhap == email).FirstOrDefault();
            var configmail    = db.ConfigMails.Where(x => x.smtpType == 2).FirstOrDefault();

            if (configmail == null)
            {
                configmail = new ConfigMail();
            }
            Random pass = new Random();
            double pw   = pass.Next(0, 999999);

            checkemployer.matkhaureset = LoginMember.MD5Hash(checkemployer.Emaildangnhap) + LoginMember.MD5Hash(pw.ToString());
            string smtpUserName = configmail.smtUserName;
            string smtpPassword = configmail.smtpPassword;
            string smtpHost     = configmail.smtpHost;
            int    smtpPort     = 25;

            if (configmail.smtpPort != null)
            {
                smtpPort = int.Parse(configmail.smtpPort.ToString());
            }
            string emailTo     = checkemployer.Emaildangnhap;
            string subject     = configmail.smtpSubject;
            string mailcontent = new EmailService().RenderPartialViewToString(this, "_ActiveEmployer", checkemployer);
            string body        = mailcontent;

            if (configmail.EnableSSL == null)
            {
                configmail.EnableSSL = false;
            }
            bool         ssl     = bool.Parse(configmail.EnableSSL.ToString());
            EmailService service = new EmailService();

            bool kq = service.Send(smtpUserName, smtpPassword, smtpHost, smtpPort,
                                   emailTo, subject, body, ssl);

            db.SaveChanges();
            return(kq);
        }
        public ActionResult UploadLogo(HttpPostedFileBase logo, HttpPostedFileBase logo1, int logoid1, HttpPostedFileBase logo2, int logoid2, HttpPostedFileBase logo3, int logoid3, int logodelete1, int logodelete2, int logodelete3, string video, int mact)
        {
            var user   = db.CongTies.Where(x => x.MACT == mact).FirstOrDefault();
            var logoct = db.CongTies.Where(x => x.MACT == user.MACT).FirstOrDefault();

            if (logoct != null)
            {
                logoct.VideoCT = video;
                db.SaveChanges();
            }
            var       imgcompany = db.HinhAnhCTs.Where(x => x.MACT == user.MACT);
            HinhAnhCT img        = new HinhAnhCT();

            if (logo != null)
            {
                if (logoct.Logo != null)
                {
                    deleteimg(logoct.Logo);
                }
                logoct.Logo = "logo" + user.Emaildangnhap + logo.FileName;
                logoct.Logo = LoginMember.MD5Hash(logoct.Logo) + logo.FileName;
                string path = System.IO.Path.Combine(Server.MapPath("~/Employer_upload/"), logoct.Logo);
                logo.SaveAs(path);
                db.SaveChanges();
            }
            if (imgcompany.Count() > 0)
            {
                if (logoid1 == 0 && logoid2 == 0 && logoid3 == 0)
                {
                    foreach (var item in imgcompany)
                    {
                        deleteimg(item.AnhCT);
                    }
                    db.HinhAnhCTs.RemoveRange(imgcompany);
                    db.SaveChanges();
                }
                else
                {
                    if (logoid1 == 0)
                    {
                        var delete = db.HinhAnhCTs.Where(x => x.Id == logodelete1).FirstOrDefault();
                        if (delete != null)
                        {
                            deleteimg(delete.AnhCT);
                            db.HinhAnhCTs.Remove(delete);
                            db.SaveChanges();
                        }
                    }
                    if (logoid2 == 0)
                    {
                        var delete = db.HinhAnhCTs.Where(x => x.Id == logodelete2).FirstOrDefault();
                        if (delete != null)
                        {
                            deleteimg(delete.AnhCT);
                            db.HinhAnhCTs.Remove(delete);
                            db.SaveChanges();
                        }
                    }
                    if (logoid3 == 0)
                    {
                        var delete = db.HinhAnhCTs.Where(x => x.Id == logodelete3).FirstOrDefault();
                        if (delete != null)
                        {
                            deleteimg(delete.AnhCT);
                            db.HinhAnhCTs.Remove(delete);
                            db.SaveChanges();
                        }
                    }
                }
                if (logoid1 > 0 && logo1 != null)
                {
                    var logoimg1 = db.HinhAnhCTs.Where(x => x.Id == logoid1).FirstOrDefault();
                    deleteimg(logoimg1.AnhCT);
                    logoimg1.AnhCT = "img1" + user.Emaildangnhap;
                    logoimg1.AnhCT = LoginMember.MD5Hash(logoimg1.AnhCT) + logo1.FileName;
                    db.SaveChanges();
                    Uploadlogo(logo1, 1, mact);
                    deleteimg(logoimg1.AnhCT);
                }
                if (logoid2 > 0 && logo2 != null)
                {
                    var logoimg1 = db.HinhAnhCTs.Where(x => x.Id == logoid1).FirstOrDefault();
                    deleteimg(logoimg1.AnhCT);
                    logoimg1.AnhCT = "img2" + user.Emaildangnhap;
                    logoimg1.AnhCT = LoginMember.MD5Hash(logoimg1.AnhCT) + logo1.FileName;
                    db.SaveChanges();
                    Uploadlogo(logo1, 3, mact);
                }
                if (logoid3 > 0 && logo3 != null)
                {
                    var logoimg1 = db.HinhAnhCTs.Where(x => x.Id == logoid1).FirstOrDefault();
                    deleteimg(logoimg1.AnhCT);
                    logoimg1.AnhCT = "img3" + user.Emaildangnhap;
                    logoimg1.AnhCT = LoginMember.MD5Hash(logoimg1.AnhCT) + logo1.FileName;
                    db.SaveChanges();
                    Uploadlogo(logo1, 3, mact);
                }
                if (logo1 != null)
                {
                    var delete1 = db.HinhAnhCTs.Where(x => x.MACT == user.MACT).FirstOrDefault();
                    if (delete1 != null)
                    {
                        deleteimg(delete1.AnhCT);
                        db.HinhAnhCTs.Remove(delete1);
                        db.SaveChanges();
                    }
                    Uploadlogo(logo1, 1, mact);
                    img.AnhCT = "img1" + user.Emaildangnhap;
                    img.AnhCT = LoginMember.MD5Hash(img.AnhCT) + logo1.FileName;
                    img.MACT  = user.MACT;
                    db.HinhAnhCTs.Add(img);
                    db.SaveChanges();
                }
                if (logo2 != null)
                {
                    var delete1 = db.HinhAnhCTs.Where(x => x.MACT == user.MACT).OrderBy(x => x.Id).Skip(1).FirstOrDefault();
                    if (delete1 != null)
                    {
                        deleteimg(delete1.AnhCT);
                        db.HinhAnhCTs.Remove(delete1);
                        db.SaveChanges();
                    }
                    Uploadlogo(logo2, 2, mact);
                    img.AnhCT = "img2" + user.Emaildangnhap;
                    img.AnhCT = LoginMember.MD5Hash(img.AnhCT) + logo2.FileName;
                    img.MACT  = user.MACT;
                    db.HinhAnhCTs.Add(img);
                    db.SaveChanges();
                }
                if (logo3 != null)
                {
                    var delete1 = db.HinhAnhCTs.Where(x => x.MACT == user.MACT).OrderBy(x => x.Id).Skip(2).FirstOrDefault();
                    if (delete1 != null)
                    {
                        deleteimg(delete1.AnhCT);
                        db.HinhAnhCTs.Remove(delete1);
                        db.SaveChanges();
                    }
                    img.AnhCT = "img3" + user.Emaildangnhap;
                    img.AnhCT = LoginMember.MD5Hash(img.AnhCT) + logo3.FileName;
                    img.MACT  = user.MACT;
                    db.HinhAnhCTs.Add(img);
                    db.SaveChanges();
                    Uploadlogo(logo3, 3, mact);
                }
            }
            else
            {
                if (logo1 != null)
                {
                    Uploadlogo(logo1, 1, mact);
                    img.AnhCT = "img1" + user.Emaildangnhap;
                    img.AnhCT = LoginMember.MD5Hash(img.AnhCT) + logo1.FileName;
                    img.MACT  = user.MACT;
                    db.HinhAnhCTs.Add(img);
                    db.SaveChanges();
                }
                if (logo2 != null)
                {
                    Uploadlogo(logo2, 2, mact);
                    img.AnhCT = "img2" + user.Emaildangnhap;
                    img.AnhCT = LoginMember.MD5Hash(img.AnhCT) + logo2.FileName;
                    img.MACT  = user.MACT;
                    db.HinhAnhCTs.Add(img);
                    db.SaveChanges();
                }
                if (logo3 != null)
                {
                    img.AnhCT = "img3" + user.Emaildangnhap;
                    img.AnhCT = LoginMember.MD5Hash(img.AnhCT) + logo3.FileName;
                    img.MACT  = user.MACT;
                    db.HinhAnhCTs.Add(img);
                    db.SaveChanges();
                    Uploadlogo(logo3, 3, mact);
                }
            }
            return(Json(new { status = "SUCCESS" }));
        }