Пример #1
0
        protected async void Session_Start(object sender, EventArgs e)
        {
            NotificationComponent       NC  = new NotificationComponent();
            ApplicationMandatoryService obj = new ApplicationMandatoryService();
            var userId = HttpContext.Current.Session["UserId"] as string;

            if (userId != null)
            {
                var data = await obj.GetLastLogindb(userId);

                var currentTime = data.CreatedDateandTime;
                HttpContext.Current.Session["LastUpdated"] = currentTime;
                NC.RegisterNotification(currentTime);
            }
        }
Пример #2
0
        public async Task <ActionResult> Login(LoginRegistration model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = await UserManager1.FindByEmailAsync(model.login.Email);

            Session["UserId"] = user.Id;
            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            if (user != null)
            {
                if (user.EmailConfirmed == true)
                {
                    var result = await SignInManager.PasswordSignInAsync(user.UserName, model.login.Password, model.login.RememberMe, shouldLockout : false);



                    switch (result)
                    {
                    case SignInStatus.Success:



                        if (user.UserActive == false || user.UserActive == null)
                        {
                            user.UserActive = true;
                            var result2 = UserManager1.Update(user);
                        }

                        Session["usertype"] = user.Usertype;
                        var usertype = user.Usertype;
                        Session["EmailId"] = model.login.Email;

                        if (usertype == 1)
                        {
                            try
                            {
                                ApplicationMandatoryService AmService = new ApplicationMandatoryService();
                                NotificationComponent       NC        = new NotificationComponent();
                                AmService.SaveUserSession();

                                var data = await AmService.GetLastLogindb(Session["UserId"] as string);

                                var currentTime = data.CreatedDateandTime;
                                Session["LastUpdated"] = currentTime;
                                NC.RegisterNotification(currentTime);
                                return(RedirectToAction("Home", "OrganizerBasicDetails"));
                            }
                            catch (Exception ex)
                            {
                                return(View("~/Views/Errorpage/Errorpage.cshtml"));
                            }
                        }
                        else
                        {
                            try
                            {
                                ViewBag.UserType = "Participants";
                                ApplicationMandatoryService AmService = new ApplicationMandatoryService();

                                AmService.SaveUserSession();
                                NotificationComponent NC = new NotificationComponent();
                                AmService.SaveUserSession();

                                var data = await AmService.GetLastLogindb(User.Identity.GetUserId());

                                var currentTime = data.CreatedDateandTime;
                                Session["LastUpdated"] = currentTime;
                                NC.RegisterNotification(currentTime);
                                return(RedirectToAction("ParticipantHome", "Participants"));
                            }
                            catch (Exception ex)
                            {
                                return(View("~/Views/Errorpage/Errorpage.cshtml"));
                            }
                        }

                    case SignInStatus.LockedOut:
                        return(View("Lockout"));

                    case SignInStatus.RequiresVerification:
                        return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.login.RememberMe }));

                    case SignInStatus.Failure:
                    default:
                        ModelState.AddModelError("", "Invalid login attempt.");
                        return(View(model));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Confirm email address by clicking on link sent to yur email id.");
                }
            }
            return(View(model));
        }