public ActionResult AccountVerification_POST(string p)
 {
     ViewBag.EncryptedEmail = p;
     if (!string.IsNullOrEmpty(p))
     {
         string     Email                  = Crypto.Decrypt(p);
         string     ValidationKey          = null;
         User       userDetail             = db.Users.FirstOrDefault(x => x.Email == Email && x.IsEmailVerified != true && x.IsActive != true);
         MailSender sendVarificationEmail  = new Common.MailSender();
         Random     randonNumberValidation = new Random(655);
         if (userDetail != null)
         {
             if (!string.IsNullOrEmpty(userDetail.ValidationKey))
             {
                 ValidationKey = userDetail.ValidationKey;
             }
             else
             {
                 ValidationKey            = Guid.NewGuid() + DateTime.Now.ToString("ddmmyyhhmmss") + db.Users.Count() + Guid.NewGuid() + randonNumberValidation.Next(5659, 656588);
                 userDetail.ValidationKey = ValidationKey;
                 db.SaveChanges();
             }
             string Message = string.Format(@"Hi! <br /> <br /> Your ooladata.com account has been created. <br /> <br/ >
                                             Please Click on following link to confirm your account<br /> <br >
                                             <a href='{1}'>Confirm email address</a> {2}", "", "http://ooladata.com/Account/Verify?u=" + ValidationKey,
                                            "<br /><br /> Thanks, <br /> OolaData Team");
             sendVarificationEmail.SendEmail("OolaData Account Verification", Email, Message);
             TempData["Msg"] = "A verification email has been send to your email <b>" + Email + "</b> <br/> Please Check your email to Verify account. Thanks!";
             return(View());
         }
     }
     return(HttpNotFound());
 }
 public ActionResult Login(string Email, string Password, string ReturnUrl)
 {
     if (ModelState.IsValid)
     {
         var loginUser = db.Users.FirstOrDefault(u => u.Email == Email && u.Password == Password);
         if (loginUser != null)
         {
             Session["UserProfilePath"] = loginUser.ProfilePic;
             Session["UserFirstName"]   = !string.IsNullOrEmpty(loginUser.FirstName) ? loginUser.FirstName.ToUpper() : "Hi!";
             FormsAuthentication.SetAuthCookie(Convert.ToString(loginUser.Id), true);
             if (loginUser.IsEmailVerified != true)
             {
                 MailSender sendVarificationEmail  = new Common.MailSender();
                 Random     randonNumberValidation = new Random(655);
                 string     ValidationKey          = null;
                 if (!string.IsNullOrEmpty(loginUser.ValidationKey))
                 {
                     ValidationKey = loginUser.ValidationKey;
                 }
                 else
                 {
                     ValidationKey           = Guid.NewGuid() + DateTime.Now.ToString("ddmmyyhhmmss") + db.Users.Count() + Guid.NewGuid() + randonNumberValidation.Next(5659, 656588);
                     loginUser.ValidationKey = ValidationKey;
                     db.SaveChanges();
                 }
                 string Message = string.Format(@"Hi! <br /> <br /> Your ooladata.com account has been created. <br /> <br/ >
                                             Please Click on following link to confirm your account<br /> <br >
                                             <a href='{1}'>Confirm email address</a> {2}", "", "http://ooladata.com/Account/Verify?u=" + ValidationKey,
                                                "<br /><br /> Thanks, <br /> OolaData Team");
                 sendVarificationEmail.SendEmail("OolaData Account Verification", Email, Message);
                 TempData["Msg"] = "A verification email has been send to your email <b>" + Email + "</b> <br/> Please Check your email to Verify account. Thanks!";
                 string EncryptedEmail = Common.Crypto.Encrypt(loginUser.Email);
                 return(RedirectToAction("AccountVerification", new { p = EncryptedEmail }));
             }
             if (!string.IsNullOrEmpty(ReturnUrl))
             {
                 return(Redirect(ReturnUrl));
             }
             return(RedirectToAction("Index", "Page"));
         }
         else
         {
             ModelState.AddModelError("", "The Email/password is Incorrect.");
         }
     }
     return(View());
 }
        public ActionResult Signup(User userData)
        {
            if (userData.Subdomain.ToLower().Contains("www.") || userData.Subdomain.ToLower().Contains("www") || userData.Subdomain.ToLower().Contains("*") || userData.Subdomain.ToLower().Contains(".") || userData.Subdomain.ToLower().Contains("http") || userData.Subdomain.ToLower().Contains("http://") || userData.Subdomain.ToLower().Contains("https://"))
            {
                ModelState.AddModelError("", "Sorry this Sudomain can't be used!");
                return(View());
            }
            var isDataExist = db.Users.FirstOrDefault(x => x.Subdomain.ToLower() == userData.Subdomain);

            if (isDataExist != null)
            {
                ModelState.AddModelError("", "Sorry, This subdomain already exist!");
                return(View());
            }
            MailSender sendVarificationEmail  = new Common.MailSender();
            Random     randonNumberValidation = new Random(655);
            string     ValidationKey          = Guid.NewGuid() + DateTime.Now.ToString("ddmmyyhhmmss") + db.Users.Count() + Guid.NewGuid() + randonNumberValidation.Next(5659, 656588);

            if (ModelState.IsValid)
            {
                using (var tran = db.Database.BeginTransaction())
                {
                    try
                    {
                        User   user         = db.Users.FirstOrDefault(x => x.Email == userData.Email);
                        string EncryptEmail = string.Empty;
                        string UserEmail    = string.Empty;

                        if (user != null)
                        {
                            if (user.IsEmailVerified != true)
                            {
                                if (!string.IsNullOrEmpty(user.ValidationKey))
                                {
                                    ValidationKey = user.ValidationKey;
                                }
                                else
                                {
                                    ValidationKey      = Guid.NewGuid() + DateTime.Now.ToString("ddmmyyhhmmss") + db.Users.Count() + Guid.NewGuid() + randonNumberValidation.Next(5659, 656588);
                                    user.ValidationKey = ValidationKey;
                                }
                                user.Password  = userData.Password;
                                user.Email     = user.Email.ToLower();
                                EncryptEmail   = Crypto.Encrypt(user.Email);
                                user.Subdomain = user.Subdomain.ToLower();
                                UserEmail      = user.Email.ToLower();
                            }
                            else
                            {
                                tran.Dispose();
                                ModelState.AddModelError("", "This email is already registered with us.");
                                return(View());
                            }
                        }
                        else
                        {
                            userData.Email = userData.Email.ToLower();
                            userData.AccountCreateDateTime = DateTime.UtcNow;
                            userData.IsActive        = false;
                            userData.Subdomain       = userData.Subdomain.ToLower();
                            userData.IsEmailVerified = false;
                            userData.ValidationKey   = ValidationKey;
                            db.Users.Add(userData);
                        }
                        if (user == null)
                        {
                            EncryptEmail = Crypto.Encrypt(userData.Email);
                            UserEmail    = userData.Email.ToLower();
                        }
                        db.SaveChanges();

                        string Message = string.Format(@"Hi! <br /> <br /> Your ooladata.com account has been created. <br /> <br/ >
                                                    Please Click on following link to confirm your account<br /> <br >
                                                    <a href='{1}'>Confirm email address</a> {2}", "", "http://ooladata.com/Account/Verify?u=" + ValidationKey,
                                                       "<br /><br /> Thanks, <br /> OolaData Team");
                        if (sendVarificationEmail.SendEmail("OolaData Account Verification", UserEmail, Message) != true)
                        {
                            throw new Exception("Email Sending Failed");
                        }
                        TempData["Msg"] = "A verification email is send to your email <b>" + UserEmail + "</b> <br/> Please Check your email to Verify account. Thanks!";
                        tran.Commit();
                        return(RedirectToAction("AccountVerification", "Account", new { p = EncryptEmail }));
                    }
                    catch (Exception er)
                    {
                        tran.Rollback();
                        TempData["Msg"] = "<p class='text-error'>There is an error. Please try again!<br />OR<br />Contact to Support Team!</p> ERROR: " + "4040";
                        return(RedirectToAction("Signup"));
                    }
                }
            }
            else
            {
                // ModelState.AddModelError("", "Please fill Required filed.");
            }

            return(View());
        }