public ActionResult Create([Bind(Include = "UserId,Email,UPassword,First_Name,Last_Name,Gender,DOB,Address1,Address2,City,State,Country,Phone,IsVerified,IsLocked,IsActive,CreatedDate")] TAC_User tAC_User)
        {
            if (ModelState.IsValid)
            {
                tAC_User.UserId = Guid.NewGuid();
                db.TAC_User.Add(tAC_User);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Country = new SelectList(db.TAC_Country, "CountryId", "CountryName", tAC_User.Country);
            ViewBag.Country = new SelectList(db.TAC_Country, "CountryId", "CountryName", tAC_User.Country);
            return(View(tAC_User));
        }
 public ActionResult Register(TAC_User user)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var list = db.TAC_User.ToList();
             if (user.TermsAndConditions)
             {
                 if ((list.Where(x => x.Email.Equals(user.Email)).Count() <= 0))
                 {
                     user.UserId      = Guid.NewGuid();
                     user.IsAdmin     = false;
                     user.IsActive    = true;
                     user.IsLocked    = false;
                     user.CreatedDate = DateTime.Now;
                     user.UPassword   = FormsAuthentication.HashPasswordForStoringInConfigFile(user.UPassword, "SHA1");
                     db.TAC_User.Add(user);
                     db.SaveChanges();
                     SendMail(user);
                     return(RedirectToAction("Login", "Login"));
                 }
                 else
                 {
                     ViewBag.ErrorMessage = "Email ID already exists. Please try another one.";
                     //ViewBag.ErrorMessage.ForeColor = System.Drawing.Color.Red;
                 }
             }
             else
             {
                 ViewBag.ErrorMessage = "Please check the Terms and Conditions.";
             }
         }
     }
     catch (Exception ex)
     {
         ViewBag.ErrorMessage = "Technical Problem. Please try again.";
         // ViewBag.ErrorMessage.ForeColor = System.Drawing.Color.Red;
     }
     return(View());
 }
        public ActionResult SaveToDb(TAC_ContactUs contact)
        {
            contact.ContactId  = Guid.NewGuid();
            contact.PostedDate = DateTime.Now;
            db.TAC_ContactUs.Add(contact);
            db.SaveChanges();
            ViewBag.Message = "Your comment has been saved successfully!";
            HelperClasses.SendEmail obj = new HelperClasses.SendEmail();
            StringBuilder           sb  = new StringBuilder();

            sb.Append("<b>Dear Admin</b>, <br/>");
            sb.Append("A contact has just visited our site. Here are the details <br/><br/>");
            sb.Append("<b>Contact Name</b> : " + contact.Name + "<br/>");
            sb.Append("<b>Contact ID : </b>" + contact.ContactId + "<br/>");
            sb.Append("<b>Contact Email : </b>" + contact.Email + "<br/>");
            sb.Append("<b>Contact Comment : </b>" + contact.Comment + "<br/>");
            sb.Append("<b>Posted Date : </b>" + contact.PostedDate + "<br/>");
            obj.SendEmailMessage(GetAdminEmails(), sb.ToString(), "Contact Details");
            return(View("Contact", contact));
        }
Example #4
0
        public ActionResult Login(LoginModel model)
        {
            try
            {
                var emailEntered = db.TAC_User.ToList().Where(x => x.Email.Equals(model.Email)).FirstOrDefault();
                if (emailEntered == null)
                {
                    ViewBag.Message = "Entered Email ID does not exist. Please click on register.";
                }
                else
                {
                    string password = FormsAuthentication.HashPasswordForStoringInConfigFile(model.UPassword, "SHA1");
                    #region To Lock Acccout if more than 3 wrong passwords are entered

                    Dictionary <string, int> myDictionary = (Dictionary <string, int>)Session["LockEmailList"];
                    if (Session["LockEmailList"] != null)
                    {
                        if (!myDictionary.ContainsKey(model.Email))
                        {
                            myDictionary.Add(model.Email, 0);
                        }
                        else
                        {
                            string actualPassword = db.TAC_User.ToList().Where(x => x.Email.Equals(model.Email)).FirstOrDefault().UPassword;
                            if (!password.Equals(actualPassword) && myDictionary.ContainsKey(model.Email))
                            {
                                count = myDictionary[model.Email];
                                count++;
                                myDictionary[model.Email] = count;
                            }
                        }
                        Session["LockEmailList"] = myDictionary;
                    }

                    #region lock account using cookie

                    //var list = usersList.ToList().Where(x => x.StringData.Equals(model.Email));
                    //if (!model.UPassword.Equals(actualPassword))
                    //    count++;

                    //HttpCookie chkLock = new HttpCookie("lock");
                    //chkLock.Expires = DateTime.Now.AddSeconds(3600);
                    //chkLock.Value = count.ToString();
                    //Response.Cookies.Add(chkLock);

                    //HttpCookie enteredEmail = new HttpCookie("newEmail");
                    //enteredEmail.Expires = DateTime.Now.AddSeconds(3600);
                    //enteredEmail.Value = model.Email;
                    //Response.Cookies.Add(enteredEmail);

                    //if (Request.Cookies["lock"] != null)
                    //{
                    //    string actualPassword = db.TAC_User.ToList().Where(x => x.Email.Equals(model.Email)).FirstOrDefault().UPassword;
                    //    if (!model.UPassword.Equals(actualPassword) && model.Email.Equals(enteredEmail.Value))
                    //        count++;
                    //    chkLock.Value = count.ToString();
                    //}

                    #endregion

                    var element = db.TAC_User.ToList().Where(
                        x => x.Email.Equals(model.Email) &&
                        x.UPassword.Equals(password)).FirstOrDefault();

                    if (myDictionary[model.Email] >= 3)
                    {
                        Guid id     = db.TAC_User.ToList().Where(x => x.Email.Equals(model.Email)).FirstOrDefault().UserId;
                        var  record = db.TAC_User.Find(id);
                        record.IsLocked = true;
                        db.TAC_User.Attach(record);
                        db.Entry(record).Property(e => e.IsLocked).IsModified = true;
                        db.SaveChanges();

                        element = db.TAC_User.ToList().Where(x => x.Email.Equals(model.Email)).FirstOrDefault();
                    }
                    #endregion

                    Guid id1     = element != null ? element.UserId : Guid.Empty;
                    var  record1 = db.TAC_User.Find(id1);
                    if (record1 != null)
                    {
                        if (record1.IsVerified == null || record1.IsVerified == false)
                        {
                            ViewBag.Message = "Your account has not been verified yet. Please contact the Administrator";
                        }
                        else if (record1.IsLocked == true)
                        {
                            ViewBag.Message = "You have entered 3 incorrect passwords. So your account has been locked. Please contact the Administrator";
                        }
                        else if (record1.IsActive == false || record1.IsActive == null)
                        {
                            ViewBag.Message = "Your account has been de-activated. Please contact the Administrator";
                        }
                        else
                        {
                            Session["User"] = element;
                            #region Code for "Remember me" checkbox

                            HttpCookie chkEmail = new HttpCookie("email");

                            if (model.RememberMe)
                            {
                                chkEmail.Expires = DateTime.Now.AddSeconds(3600);
                                chkEmail.Value   = model.Email;
                                Response.Cookies.Add(chkEmail);
                            }
                            else
                            {
                                if (Response.Cookies["email"] != null)
                                {
                                    chkEmail.Expires = DateTime.Now.AddDays(-1D);
                                    Response.Cookies.Add(chkEmail);
                                }
                            }
                            #endregion
                            // Success, create non-persistent authentication cookie.
                            FormsAuthentication.SetAuthCookie(model.Email, false);
                            FormsAuthenticationTicket ticket1 = new FormsAuthenticationTicket(1, model.Email, DateTime.Now, DateTime.Now.AddMinutes(5), false, "UserData");
                            HttpCookie cookie1 = new HttpCookie(
                                FormsAuthentication.FormsCookieName,
                                FormsAuthentication.Encrypt(ticket1));
                            Response.Cookies.Add(cookie1);

                            if (Request.QueryString["ReturnUrl"] == null && record1.IsAdmin == true)
                            {
                                Response.Redirect("/Admin/Index");
                            }
                            else if (Request.QueryString["ReturnUrl"] == null && record1.IsAdmin == false && Session["returnUrl"] != null)
                            {
                                Response.Redirect(Session["returnUrl"].ToString());
                            }
                            else
                            {
                                Response.Redirect("/Home/Index");
                            }
                        }
                    }
                    else
                    {
                        ViewBag.Message = "Please Enter correct Email/Password.";
                    }
                }
            }
            catch (Exception e)
            {
            }
            return(View(model));
        }
        public ActionResult PostAd(PostAdModel postAdModel, HttpPostedFileBase fileUpload)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    postAdModel.Classified.Summary    = postAdModel.Classified.Description;
                    postAdModel.Classified.PostedDate = DateTime.Now;
                    if (Session["User"] != null)
                    {
                        TAC_User model = (TAC_User)Session["User"];
                        postAdModel.Classified.CreatedBy = model.UserId;
                    }
                    else
                    {
                        return(View());
                    }
                    if (Session["categoryID"] != null)
                    {
                        postAdModel.Classified.CategoryId = (int)Session["categoryID"];
                    }
                    else
                    {
                        ModelState.AddModelError("CategoryId", "Please select category");
                        return(View(model: postAdModel));
                    }
                    //fileupload logic
                    if (Request.Files.Count > 0)
                    {
                        int MaxContentLength = 1024 * 1024 * 3; //3 MB
                        var file             = Request.Files[0];

                        if (file != null && file.ContentLength > 0 && file.ContentLength < MaxContentLength)
                        {
                            var fileName = Path.GetFileName(file.FileName);
                            var path     = Path.Combine(Server.MapPath("../Resources/Uploaded_Images/"), fileName);
                            file.SaveAs(path);
                            postAdModel.Classified.ClassifiedImage = Path.Combine("../Resources/Uploaded_Images/", fileName);
                        }
                        else
                        {
                            if (file.ContentLength > MaxContentLength)
                            {
                                ViewBag.Message = "Please upload an image less 3MB ";
                            }
                        }
                    }

                    dbContext.TAC_Classified.Add(postAdModel.Classified);
                    dbContext.SaveChanges();
                    postAdModel.User.ClassifiedId = postAdModel.Classified.ClassifiedId;
                    dbContext.TAC_ClassifiedContact.Add(postAdModel.User);
                    dbContext.SaveChanges();

                    return(RedirectToAction("MyAccount"));
                }
            }
            catch (Exception ex)
            {
                ViewBag.Message = "Sorry, your data was not saved.";
            }
            return(View(postAdModel));
        }