Exemplo n.º 1
0
        public ActionResult LogIn(string userName, string password)
        {
            if (Session["CustomerID"] == null)
            {
                try
                {
                    using (var context = new TravelExpertsEntities3())
                    {
                        var getUser = (from s in context.Customers where s.CustUsername == userName select s).FirstOrDefault();
                        if (getUser != null)
                        {
                            //var hashCode = Helper.GeneratePassword(10);   //get the salt from the database
                            //Password Hasing Process Call Helper Class Method
                            // var encodingPasswordString = Helper.EncodePassword(password, hashCode);  //has the input password again the salt stored in the database
                            var encodingPasswordString = Helper.HashEncrypt(password);  //encrypt pass word before checking database
                            Session["CustomerID"]   = getUser.CustomerId.ToString();
                            Session["CustomerName"] = getUser.CustFirstName;

                            //Check Login Detail User Name Or Password
                            var query = (from s in context.Customers where (s.CustUsername == userName) && s.CustPassword.Equals(encodingPasswordString) select s).FirstOrDefault();
                            if (query != null)
                            {
                                //RedirectToAction("Details/" + id.ToString(), "FullTimeEmployees");
                                //return View("../Admin/Registration"); url not change in browser
                                if (Session["SelectedPackageID"] == null)
                                {
                                    return(RedirectToAction("Index", "Bookings"));
                                }
                                else
                                {
                                    return(RedirectToAction("Details", "Packages"));
                                }
                            }
                            ViewBag.ErrorMessage = "Invallid User Name or Password";
                            return(View());
                        }
                        ViewBag.ErrorMessage = "Invallid User Name or Password";
                        return(View());
                    }
                }
                catch (Exception)
                {
                    ViewBag.ErrorMessage = " Some database error ocurred, Please try again";
                    return(View());
                }
            }
            else
            {
                return(RedirectToAction("Index", "Packages"));
            }
        }
Exemplo n.º 2
0
        public ActionResult Registration(Customer customer)
        {
            try
            {
                using (var context = new TravelExpertsEntities3())
                {
                    var    chkUser      = (from s in context.Customers where s.CustUsername == customer.CustUsername select s).FirstOrDefault();
                    string name         = customer.CustFirstName; //get the customer first name from the customer object
                    string username     = customer.CustUsername;  //get the customer username from the customer object
                    string userPassword = customer.CustPassword;  //get the customer password from the customer object
                    if (chkUser == null)
                    {
                        var password = Helper.HashEncrypt(customer.CustPassword);

                        customer.CustPassword    = password;
                        customer.ConfirmPassword = password;

                        context.Customers.Add(customer);
                        context.SaveChanges();
                        SendEmail(customer.CustEmail, "Registration Confirmed",
                                  $"<p>Hi {name},<br/>Thank you for registering with Travel Experts where you explore, journey, discover and adventure.<br/>" +
                                  $"Your username: {username}<br/> Your password: {userPassword}<br/> <br/> Travel Experts</p>");

                        ModelState.Clear();
                        ModelState.Clear();
                        ViewBag.SuccessMessage = "Registration Successful";
                        //return RedirectToAction("LogIn", "Login");
                    }
                    else
                    {
                        ViewBag.ErrorMessage = "Username Already Exists! Please enter a new username.";
                    }

                    return(View());
                }
            }
            catch (Exception e)
            {
                ViewBag.ErrorMessage = "Some exception occured" + e;
                return(View());
            }
        }