示例#1
0
        public ActionResult ConfirmEmail(User user, string code)
        {
            ConfirmGmail confirmGmail = (ConfirmGmail)Session["confirmemail"];


            if (confirmGmail.strContent == code)
            {
                MD5 md5 = new MD5CryptoServiceProvider();
                md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(confirmGmail.pass));

                byte[] result = md5.Hash;

                StringBuilder strBuilder = new StringBuilder();
                for (int i = 0; i < result.Length; i++)
                {
                    strBuilder.Append(result[i].ToString("x2"));
                }

                user.user_pass = strBuilder.ToString();

                user.user_email = confirmGmail.strEmailReceived;

                user.user_nicename       = null;
                user.user_datecreated    = DateTime.Now;
                user.user_token          = Guid.NewGuid().ToString();
                user.user_role           = 0;
                user.user_datelogin      = DateTime.Now;
                user.user_activate       = true;
                user.user_phone          = "0";
                user.user_address        = null;
                user.user_img            = null;
                user.user_sex            = null;
                user.user_link_facebok   = null;
                user.user_link_github    = null;
                user.user_hobby_work     = null;
                user.user_hobby          = null;
                user.user_activate_admin = true;
                user.user_date_born      = null;
                user.user_popular        = 0;
                user.user_gold_medal     = 0;
                user.user_silver_medal   = 0;
                user.user_bronze_medal   = 0;
                user.user_vip_medal      = 0;
                user.provincial_id       = null;
                user.district_id         = null;
                user.commune_id          = null;
                db.Users.Add(user);
                db.SaveChanges();
                Session["user"]            = user;
                Session["NotRegistration"] = null;
                return(RedirectToAction("RegisterPersonalInformation"));
            }
            else
            {
                Session["notification"] = "Sai mã xác nhận";
                return(Redirect(Request.UrlReferrer.ToString()));
            }
        }
示例#2
0
        public ActionResult Register([Bind(Include = "user_id,user_pass,user_nicename,user_email,user_datecreated,user_token,user_role,user_datelogin,user_activate,user_address,user_img,user_sex,user_link_facebok,user_link_github,user_hobby_work,user_hobby,user_activate_admin,user_date_born,user_popular,user_gold_medal,user_silver_medal,user_bronze_medal,user_vip_medal,provincial_id,district_id,commune_id,user_phone")] User user, ConfirmGmail confirmGmail)
        {
            User ruser = db.Users.SingleOrDefault(n => n.user_email == user.user_email);

            if (ruser == null)
            {
                try
                {
                    WebMail.SmtpServer = "smtp.gmail.com"; //Máy chủ gmail.
                    WebMail.SmtpPort   = 587;              // Cổng
                    WebMail.SmtpUseDefaultCredentials = true;
                    //Gửi gmail với giao thức bảo mật.
                    WebMail.EnableSsl = true;
                    //Tài khoản dùng để đăng nhập vào gmail để gửi.
                    WebMail.UserName = "******";
                    WebMail.Password = "******";
                    // Nội dung gửi.
                    WebMail.From = "*****@*****.**";

                    Random random = new Random();

                    confirmGmail.pass             = user.user_pass;
                    confirmGmail.strEmailReceived = user.user_email;
                    confirmGmail.strTitle         = "Mã xác nhận : ";
                    confirmGmail.strContent       = random.Next(1000, 9999).ToString();
                    Session["confirmemail"]       = confirmGmail;

                    //Gửi gmail.
                    WebMail.Send(to: confirmGmail.strEmailReceived, subject: confirmGmail.strTitle, body: confirmGmail.strContent, isBodyHtml: true);
                    ViewBag.thongbao = "Gmail được gửi thành công";
                    return(Redirect("/Account/ConfirmEmail"));
                }
                catch (Exception)
                {
                    ViewBag.notification = "Không gửi được email";
                    return(Redirect(Request.UrlReferrer.ToString()));
                }
            }
            else
            {
                Session["NotRegistration"] = "<p class='remember' style='color:#721c24; background-color:#f8d7da; border-color:#f5c6cb; padding: .75rem 1.25rem; border: 1px solid transparent; border-radius: .25rem; line-height: 1.5;'>Emai này đã được đăng ký !</p> ";
                return(Redirect(Request.UrlReferrer.ToString()));
            }
        }