Exemple #1
0
        public ActionResult Login(user model)
        {
            using (var context = new reviewmodeldb())
            {
                bool isValid = context.Users.Any(x => x.email == model.email && x.Password == model.Password);
                if (isValid)
                {
                    Session["email"] = model.email;
                    FormsAuthentication.SetAuthCookie(model.email, false);
                    return(RedirectToAction("Index", "Home"));
                }

                ModelState.AddModelError("", "Invalid username and password");
                return(View());
            }
        }
Exemple #2
0
        public ActionResult AdminLogin(adminn model)
        {
            using (var context = new reviewmodeldb())
            {
                bool isValid = context.Admins.Any(x => x.email == model.email && x.password == model.password);
                if (isValid)
                {
                    Session["admin"] = model.email;
                    FormsAuthentication.SetAuthCookie(model.email, false);
                    return(RedirectToAction("Index", "categories"));
                }

                ModelState.AddModelError("", "Invalid username and password");
                return(View());
            }
            //return View();
        }
Exemple #3
0
 public ActionResult forgot(user model)
 {
     using (var context = new reviewmodeldb())
     {
         var a = context.Users.FirstOrDefault(x => x.email == model.email);
         if (a != null)
         {
             Random random = new Random();
             int    value  = random.Next(10000);
             Session["otp"]        = value;
             Session["forgotmail"] = model.email;
             //  ViewBag["forgot"]= model.email;
             var senderEmail   = new MailAddress("*****@*****.**", "Tanuj DOshi");
             var receiverEmail = new MailAddress(model.email, "Receiver");
             var password      = "******";
             var sub           = "Thank You for your Review";
             var body          = "Your OTP Is!!" + value;
             var smtp          = new SmtpClient
             {
                 Host                  = "smtp.gmail.com",
                 Port                  = 587,
                 EnableSsl             = true,
                 DeliveryMethod        = SmtpDeliveryMethod.Network,
                 UseDefaultCredentials = false,
                 Credentials           = new NetworkCredential(senderEmail.Address, password)
             };
             using (var mess = new MailMessage(senderEmail, receiverEmail)
             {
                 Subject = "Thank you",
                 Body = body
             })
             {
                 smtp.Send(mess);
             }
             return(RedirectToAction("forgotone", "Account"));
             // Response.Write("<script>alert('Main Sef')</script>");
         }
         else
         {
             Response.Write("<script>alert('Email Not Found')</script>");
         }
     }
     return(View());
 }
Exemple #4
0
        public ActionResult Registeruser(user model)
        {
            using (var context = new reviewmodeldb())
            {
                // bool isValid = context.Users.Any(x => x.email == model.email && x.Password == model.Password);

                context.Users.Add(model);
                context.SaveChanges();
                ModelState.AddModelError("", "Something Went Wrong!!");
                return(RedirectToAction("Login", "Account"));
                //  return View();
            }

            /* try
             * {
             *   var context = new reviewmodeldb();
             *   context.Users.Add(model);
             *   context.SaveChanges();
             *
             *
             *
             *   return RedirectToAction("Login");
             * }
             * catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
             * {
             *   Exception raise = dbEx;
             *   foreach (var validationErrors in dbEx.EntityValidationErrors)
             *   {
             *       foreach (var validationError in validationErrors.ValidationErrors)
             *       {
             *           string message = string.Format("{0}:{1}",
             *               validationErrors.Entry.Entity.ToString(),
             *               validationError.ErrorMessage);
             *           // raise a new exception nesting
             *           // the current instance as InnerException
             *           raise = new InvalidOperationException(message, raise);
             *       }
             *   }
             *   throw raise;
             * }
             * // return View();*/
        }