//[HttpPost]
        public ActionResult Sent(string name, string aemail, string message = "")
        {
            //try
            //{
            Contact model = new Contact();

            model.Id       = Public.GetID2();
            model.Name     = name;
            model.Email    = aemail;
            model.Contents = message;
            model.DateSend = DateTime.Now;
            model.UserId   = 1;

            var    ms       = db.MailServers.Find(4);
            string userName = ms.UserName;
            string password = ms.Password;
            string smtpHost = ms.Host;            //nếu dùng gmail thì:smtp.gmail.com
            int    smtpPort = int.Parse(ms.Port); //toi dùng port của gmail

            SentContact sc = new SentContact();

            sc.ToEmail = model.Email;    //các liên hệ sẽ gởi về email này
            sc.Content = "Chúc mừng bạn " + model.Name + " đã liên hệ thành công!";
            sc.Subject = "Liên hệ";
            string body = string.Format(sc.Content);

            EmailService email = new EmailService();

            bool result = email.Send(userName, password, smtpHost, smtpPort, sc.ToEmail, sc.Subject, body);

            if (result)
            {
                db.Contacts.Add(model);
                db.SaveChanges();
                TempData["success"] = "Liên hệ thành công!";
            }
            else
            {
                //TempData["error"] = "Liên hệ lỗi, mời bạn thực hiện lại!";
                int.Parse("AAA");
            }

            return(PartialView("_Start"));
            //}
            //catch
            //{
            //    TempData["error"] = "Liên hệ lỗi, mời bạn thực hiện lại!";
            //    return PartialView("_Start");
            //}
        }
Example #2
0
        public ActionResult RecoverPassword(FormCollection colection, SentContact model)
        {
            //if (ModelState.IsValid)
            //{
            var    sm       = db.MailServers.Find(4);
            string userName = sm.UserName;
            string password = sm.Password;
            string smtpHost = sm.Host;
            int    smtpPort = int.Parse(sm.Port);
            //thong tin email được gởi
            string toEmail = colection["Email"];//các liên hệ sẽ gởi về email này

            var user = db.Users.Where(e => e.Email == toEmail && e.Lock == false);

            if (user.Count() > 0)
            {
                string rdPass = Public.RandomStringNumber(8);
                model.Content = "Mật khẩu mới của bạn là: " + rdPass;
                model.Subject = "Lấy lại mật khẩu";
                model.ToEmail = toEmail;

                string body = string.Format("Thông tin tài khoản:{0} </br>" +
                                            " {1}", user.First().UserName, model.Content);

                EmailService email = new EmailService();

                bool result = email.Send(userName, password, smtpHost, smtpPort, model.ToEmail, model.Subject, body);

                if (result)
                {
                    TempData["success"] = "Thông tin lấy lại mật khẩu đã đươc gủi đi thành công, Bạn vào email nhận mật khẩu mới";

                    var users = db.Users.Where(e => e.Email == toEmail).First();
                    users.PasswordHash    = Public.SHA256(rdPass);
                    db.Entry(users).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Login", "Account", null));
                    // ModelState.AddModelError("", "Bạn đã đăng ký nhận tin khuyến mại thành công");
                }
            }
            else
            {
                TempData["error"] = "Email không tồn tại, vui lòng thử lại.";
                //ModelState.AddModelError("", "Đăng ký thất bại, vui lòng thử lại");
            }
            return(View());
        }
Example #3
0
        public ActionResult ChangePass(FormCollection colection, int id, SentContact model)
        {
            var user = db.Users.Find(id);

            //if (ModelState.IsValid)
            //{
            var    sm       = db.MailServers.Find(4);
            string userName = sm.UserName;
            string password = sm.Password;
            string smtpHost = sm.Host;
            int    smtpPort = int.Parse(sm.Port);
            //thong tin email được gởi
            string pass1 = colection["PassWord"];
            string pass2 = colection["PassWordConfirm"];

            if (pass1 == pass2)
            {
                user.PasswordHash    = Public.SHA256(pass1);
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();

                model.Content = "Mật khẩu của bạn đã được thay đổi, nếu không phải là bạn thay đổi mật khẩu, liên hệ với quản trị viên theo Email: " + userName;
                model.Subject = "Đổi mật khẩu";
                model.ToEmail = user.Email;

                string body = string.Format("Thông tin tài khoản:{0} </br>" +
                                            " {1}", user.UserName, model.Content);

                EmailService email = new EmailService();

                bool result = email.Send(userName, password, smtpHost, smtpPort, model.ToEmail, model.Subject, body);

                return(RedirectToAction("Login", "Account", null));
                //if (result)
                //{
                //    TempData["success"] = "Thông tin đổi mật khẩu đã đươc gủi đi thành công, Bạn vào email nhận mật khẩu mới";
                //    // ModelState.AddModelError("", "Bạn đã đăng ký nhận tin khuyến mại thành công");
                //}
            }
            else
            {
                TempData["error"] = "Mật khẩu nhập lại không khớp!";
            }
            return(View(user));
        }
Example #4
0
        public ActionResult UserAuthentication(FormCollection colection, string id, SentContact model)
        {
            var user = db.Users.Where(e => e.UserName == id).First();

            if (user.SecurityStamp.Trim() == colection["Code"].ToString().Trim())
            {
                var    sm       = db.MailServers.Find(4);
                string userName = sm.UserName;
                string password = sm.Password;
                string smtpHost = sm.Host;
                int    smtpPort = int.Parse(sm.Port);
                //thong tin email được gởi
                user.EmailConfirmaed = true;
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();

                string link = "http://myphamtamduc.com/AdminIT/Account/Login";

                model.Content = "Chúc mừng bạn đã kích hoạt tài khoản thành công, bạn có thể vào đường dẫn sau để tiến hành đăng nhập: " + link;
                model.Subject = "Kích hoạt tài khoản";
                model.ToEmail = user.Email;

                string body = string.Format("Thông tin tài khoản:{0} </br>" +
                                            " {1}", user.UserName, model.Content);

                EmailService email = new EmailService();

                bool result = email.Send(userName, password, smtpHost, smtpPort, model.ToEmail, model.Subject, body);


                if (result)
                {
                    TempData["success"] = "Chúc mừng bạn đã kích hoạt tài khoản thành công!";
                    return(RedirectToAction("Login", "Account", null));
                }
            }
            return(View(user));
        }
Example #5
0
    public void SendMsg(string userFrom, string userTo, string newMsg, string Type)
    {
        using (SwapEntities msgEnt = new SwapEntities())
        {
            string msgFrom = userFrom;
            string msgTo   = userTo;
            string msg     = newMsg;
            string msgType = Type;
            Guid   newId;

            if (msgTo != "")
            {
                if (msg != null && msg != "")
                {
                    if (msgType == "QM")
                    {
                        var checkMsgnum = (from tbl in msgEnt.MsgEvents
                                           where tbl.UserFrom == msgFrom & tbl.UserTo == msgTo
                                           & tbl.IsRead == false
                                           select tbl).Count();

                        if (checkMsgnum == 0)
                        {
                            var checkLastMsgDate = (from tbl in msgEnt.MsgEvents
                                                    orderby tbl.When descending
                                                    where tbl.UserFrom == msgFrom & tbl.UserTo == msgTo
                                                    & tbl.IsRead == true
                                                    select tbl).FirstOrDefault();

                            if (checkLastMsgDate != null)
                            {
                                string today       = DateTime.Now.ToShortDateString();
                                string lastMsgdate = checkLastMsgDate.When.ToShortDateString();
                                if (today != lastMsgdate)
                                {
                                    UserClass uc  = new UserClass(msgTo);
                                    UserClass ucm = new UserClass(msgFrom);

                                    string recipEmail = uc.PublicEmail;

                                    EmailUsersClass sndEmail = new EmailUsersClass(msgFrom);
                                    string          body     = sndEmail.PopulateBody(uc.PublicFirstName, "You have a new message from <b>" +
                                                                                     ucm.PublicFirstName + "</b>, login at veSwap.com to" +
                                                                                     " view and respond to this message!");

                                    sndEmail.SendHtmlFormattedEmail(recipEmail, "New message from " + ucm.PublicFirstName + " at veSwap.com", body);
                                }
                            }
                        }

                        SentMessage msgSent  = new SentMessage();
                        MsgEvent    msgEvent = new MsgEvent();
                        newId = Guid.NewGuid();

                        msgEvent.UId      = newId;
                        msgEvent.When     = DateTime.Now;
                        msgEvent.UserFrom = msgFrom;
                        msgEvent.UserTo   = msgTo;
                        msgEvent.MsgType  = msgType;
                        msgEvent.IsRead   = false;
                        msgSent.UId       = newId;
                        msgSent.IsRead    = false;
                        msgSent.Message   = msg;

                        msgEnt.AddToSentMessages(msgSent);
                        msgEnt.AddToMsgEvents(msgEvent);
                        msgEnt.SaveChanges();
                    }
                    MsgEvent   msgEventrec = new MsgEvent();
                    RecMessage msgRec      = new RecMessage();
                    newId = Guid.NewGuid();

                    msgEventrec.UId      = newId;
                    msgEventrec.When     = DateTime.Now;
                    msgEventrec.UserFrom = msgFrom;
                    msgEventrec.UserTo   = msgTo;
                    msgEventrec.MsgType  = msgType;
                    msgEventrec.IsRead   = false;
                    msgRec.UId           = newId;
                    msgRec.IsRead        = false;
                    msgRec.Message       = msg;

                    msgEnt.AddToRecMessages(msgRec);
                    msgEnt.AddToMsgEvents(msgEventrec);
                    msgEnt.SaveChanges();


                    if (msgType != "NM")
                    {
                        var updateContact = (from cnt in msgEnt.Contacts
                                             where cnt.UserTo == msgTo && cnt.UserFrom == msgFrom
                                             select cnt).SingleOrDefault();

                        if (updateContact == null)
                        {
                            Contact addContact = new Contact();
                            Guid    contGuid   = Guid.NewGuid();

                            addContact.Id           = contGuid;
                            addContact.UserTo       = msgTo;
                            addContact.UserFrom     = msgFrom;
                            addContact.LastReceived = DateTime.Now;

                            msgEnt.AddToContacts(addContact);
                            msgEnt.SaveChanges();
                        }
                        else
                        {
                            updateContact.LastReceived = DateTime.Now;
                            msgEnt.SaveChanges();
                        }

                        var updateSntContact = (from snt in msgEnt.SentContacts
                                                where snt.UserTo == msgTo && snt.UserFrom == msgFrom
                                                select snt).SingleOrDefault();

                        if (updateSntContact == null)
                        {
                            SentContact addSntContact = new SentContact();
                            Guid        sntcontGuid   = Guid.NewGuid();

                            addSntContact.Id       = sntcontGuid;
                            addSntContact.UserTo   = msgTo;
                            addSntContact.UserFrom = msgFrom;
                            addSntContact.LastSent = DateTime.Now;

                            msgEnt.AddToSentContacts(addSntContact);
                            msgEnt.SaveChanges();
                        }
                        else
                        {
                            updateSntContact.LastSent = DateTime.Now;
                            msgEnt.SaveChanges();
                        }
                    }
                }
            }
        }
    }
Example #6
0
        public ActionResult Register(FormCollection colection, SentContact model)
        {
            //if (ModelState.IsValid)
            //{
            if (colection["AgreeTerms"] == "on")
            {
                var    sm       = db.MailServers.Find(4);
                string userName = sm.UserName;
                string password = sm.Password;
                string smtpHost = sm.Host;
                int    smtpPort = int.Parse(sm.Port);
                //thong tin email được gởi
                string toEmail  = colection["Email"];//các liên hệ sẽ gởi về email này
                string username = colection["UserName"];

                var user = db.Users.Where(e => e.Email == toEmail || e.UserName == username);

                if (user.Count() <= 0)
                {
                    string code = "";
                    do
                    {
                        code = Public.RandomStringNumber(8);
                    } while (db.Users.Where(e => e.SecurityStamp == code).Count() > 0);

                    string link = "http://myphamtamduc.com/AdminIT/Account/UserAuthentication/" + username;

                    User us = new User();
                    us.FullName             = username;
                    us.UserName             = username;
                    us.Email                = toEmail;
                    us.EmailConfirmaed      = false;
                    us.Lock                 = true;
                    us.PasswordHash         = Public.SHA256(colection["PassWord"]);
                    us.PhoneNumber          = "";
                    us.PhoneNumberConfirmed = false;
                    us.Avata                = "/Test/dragonviet.png";
                    us.RoleId               = "151225031247673";
                    us.SecurityStamp        = code;
                    us.Sex               = "";
                    us.LockoutEnabled    = false;
                    us.LockoutEndDateUtc = DateTime.Now;
                    us.Birthday          = DateTime.Now;
                    us.Address           = "";

                    model.Content = "Mã kích hoạt tài khoản của bạn là: " + code + " </br> Bạn vào đường dẫn sau để kích hoạt tài khoản: " + link;
                    model.Subject = "Thông tin đăng ký tài khoản";
                    model.ToEmail = toEmail;

                    string body = string.Format("Chúc mừng tài khoản:{0} đã đăng ký thành công! </br> {1}", username, model.Content);

                    EmailService email = new EmailService();

                    bool result = email.Send(userName, password, smtpHost, smtpPort, model.ToEmail, model.Subject, body);

                    if (result)
                    {
                        db.Users.Add(us);
                        db.SaveChanges();
                        TempData["success"] = "Chúc mừng bạn đã tạo tài khoản thành công!, Bạn vào email để nhận mã kích hoạt!";
                        return(RedirectToAction("UserAuthentication", "Account", new { id = username }));
                    }
                }
                else
                {
                    TempData["error"] = "Email hoặc tài khoản đã được sử dụng, vui lòng thử lại.";
                    //ModelState.AddModelError("", "Đăng ký thất bại, vui lòng thử lại");
                }
            }
            return(View(new User()));
        }