Exemplo n.º 1
0
        public override string[] GetRolesForUser(string username)
        {
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
            {
                return(null);
            }

            //check cache
            string cacheKey = string.Format("{0}_role", username);

            if (HttpRuntime.Cache[cacheKey] != null)
            {
                return((string[])HttpRuntime.Cache[cacheKey]);
            }
            string[] roles = new string[] { };
            using (KTMTicketingEntities dc = new KTMTicketingEntities())
            {
                roles = (from a in dc.Roles
                         join b in dc.UserRoles on a.RoleID equals b.RoleID
                         join c in dc.Users on b.UserID equals c.UserID
                         where c.EmailID.Equals(username)
                         select a.RoleName).ToArray <string>();
                if (roles.Count() > 0)
                {
                    HttpRuntime.Cache.Insert(cacheKey, roles, null, DateTime.Now.AddMinutes(_cacheTimeoutInMinute), Cache.NoSlidingExpiration);
                }
            }
            return(roles);
        }
Exemplo n.º 2
0
 public bool IsEmailExist(string emailID)
 {
     using (KTMTicketingEntities dc = new KTMTicketingEntities())
     {
         var v = dc.Users.Where(a => a.EmailID == emailID).FirstOrDefault();
         return(v != null);
     }
 }
Exemplo n.º 3
0
        public ActionResult Registration([Bind(Exclude = "IsEmailVerified,ActivationCode")] User user)
        {
            bool   Status  = false;
            string Message = "";

            //
            //Model Validation
            if (ModelState.IsValid)
            {
                #region //Email is already exist

                var isExist = IsEmailExist(user.EmailID);

                if (isExist)
                {
                    ModelState.AddModelError("EmailExist", "Email already exist");
                    return(View(user));
                }
                #endregion

                #region //Generate activation code
                user.ActivationCode = Guid.NewGuid();
                #endregion

                #region //Pasword Hashing
                user.Password        = Crypto.Hash(user.Password);
                user.ConfirmPassword = Crypto.Hash(user.ConfirmPassword);
                #endregion

                user.IsEmailVerified = false;

                #region //Save data to database
                using (KTMTicketingEntities dc = new KTMTicketingEntities())
                {
                    dc.Users.Add(user);
                    dc.SaveChanges();

                    //Send email to user
                    SendVerificationLinkEmail(user.EmailID, user.ActivationCode.ToString());
                    Message = "Registration successfully done. Account activation link has been send to your " +
                              "email id: " + user.EmailID;

                    Status = true;
                }
                #endregion
            }
            else
            {
                Message = "Invalid Request";
            }

            ViewBag.Message = Message;
            ViewBag.Status  = Status;
            return(View(user));
        }
Exemplo n.º 4
0
        public ActionResult Login(UserLogin login, string ReturnUrl)
        {
            string Message = "";

            using (KTMTicketingEntities dc = new KTMTicketingEntities())
            {
                var v = dc.Users.Where(a => a.EmailID == login.EmailID).FirstOrDefault();

                if (v != null)
                {
                    if (!v.IsEmailVerified)
                    {
                        ViewBag.Message = "Please verify your email first";
                        return(View());
                    }

                    if (string.Compare(Crypto.Hash(login.Password), v.Password) == 0)
                    {
                        int timeout = login.RememberMe ? 525600 : 20; // 525600 min = 1 year
                        //var ticket = FormsAuthentication.SetAuthCookie(login.EmailID, login.RememberMe);
                        var    ticket    = new FormsAuthenticationTicket(login.EmailID, login.RememberMe, timeout);
                        string encrypted = FormsAuthentication.Encrypt(ticket);
                        var    cookie    = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted);
                        cookie.Expires  = DateTime.Now.AddMinutes(timeout);
                        cookie.HttpOnly = true;
                        Response.Cookies.Add(cookie);

                        if (Url.IsLocalUrl(ReturnUrl))
                        {
                            return(Redirect(ReturnUrl));
                        }
                        else
                        {
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                    else
                    {
                        Message = "Invalid credential provided";
                    }
                }
                else
                {
                    Message = "Invalid credential provided";
                }
            }
            ViewBag.Message = Message;
            return(View());
        }
Exemplo n.º 5
0
        public ActionResult AccountSetting()
        {
            var emailID = User.Identity.Name;

            using (KTMTicketingEntities dc = new KTMTicketingEntities())
            {
                var user = dc.Users.First(a => a.EmailID == emailID);

                var viewModel = new AccountSetting
                {
                    FirstName = user.FirstName,
                    LastName  = user.LastName,
                    EmailID   = user.EmailID,
                    ICNumber  = user.ICNumber
                };
                return(View(viewModel));
            }
        }
Exemplo n.º 6
0
        public ActionResult ViewPurchasedTicket()
        {
            string emailID = HttpContext.User.Identity.Name;

            using (KTMTicketingEntities dc = new KTMTicketingEntities())
            {
                /*var tickets = dc.PurchasedTickets
                 *  .Where(t => t.EmailID == emailID)
                 *  .Where(t => t.PurchasedOn > DateTime.Now)
                 *  .OrderBy(t => t.PurchasedOn)
                 *  .ToList();*/

                var tickets = (from a in dc.PurchasedTickets
                               where a.EmailID.Equals(emailID)
                               select a).ToList();

                return(View(tickets));
            }
        }
Exemplo n.º 7
0
        public ActionResult UpdateAccountSetting(AccountSetting viewModel)
        {
            if (ModelState.IsValid)
            {
                using (KTMTicketingEntities bc = new KTMTicketingEntities())
                {
                    var emailID = User.Identity.Name;
                    var user    = bc.Users.SingleOrDefault(a => a.EmailID == emailID);

                    if (user != null)
                    {
                        user.FirstName = viewModel.FirstName;
                        user.LastName  = viewModel.LastName;
                        user.EmailID   = viewModel.EmailID;
                        user.ICNumber  = viewModel.ICNumber;

                        bc.SaveChanges();
                    }
                }
            }
            return(RedirectToAction("AccountSetting"));
        }
Exemplo n.º 8
0
        public ActionResult VerifyAccount(string id)
        {
            bool Status = false;

            using (KTMTicketingEntities dc = new KTMTicketingEntities())
            {
                dc.Configuration.ValidateOnSaveEnabled = false; // This line I have added here to avoid
                // Confirm password does not match issue on save changes
                var v = dc.Users.Where(a => a.ActivationCode == new Guid(id)).FirstOrDefault();
                if (v != null)
                {
                    v.IsEmailVerified = true;
                    dc.SaveChanges();
                    Status = true;
                }
                else
                {
                    ViewBag.Message = "Invalid Request";
                }
            }
            ViewBag.Status = Status;
            return(View());
        }
Exemplo n.º 9
0
        public ActionResult PurchaseDetails(String OriginLoc, String DestiLoc, String WayLoc, String Citizen, int Quantity)
        {
            KTMTicketingv2.Controllers.ktmPrice ktmPrice = new KTMTicketingv2.Controllers.ktmPrice(OriginLoc, DestiLoc, WayLoc, Citizen, Quantity);
            ViewBag.DestiLoc      = ktmPrice.getDestination();
            ViewBag.OriginLoc     = ktmPrice.getOrigin();
            ViewBag.Price         = ktmPrice.getPrice();
            ViewBag.WayLoc        = ktmPrice.getWay();
            ViewBag.Citizen       = ktmPrice.getCitizen();
            ViewBag.Quantity      = ktmPrice.getQuantity();
            ViewBag.DestinationID = ktmPrice.getDestinationID();
            ViewBag.OriginID      = ktmPrice.getOriginID();
            ViewBag.CitizenID     = ktmPrice.getCitizenID();
            ViewBag.WayLocID      = ktmPrice.getWayID();

            string emailID = User.Identity.Name;

            using (KTMTicketingEntities dc = new KTMTicketingEntities())
            {
                var users = dc.Users.First(a => a.EmailID == emailID);

                if (users != null)
                {
                    ViewBag.EmailID   = users.EmailID;
                    ViewBag.FirstName = users.FirstName;
                    ViewBag.LastName  = users.LastName;
                    ViewBag.ICNumber  = users.ICNumber;
                    return(View());
                }
                else
                {
                    ViewBag.Message = "Error!";
                }
            }

            return(View());
        }