public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var userService = new UserBAL();
                var user = userService.GetUserByEmailOrPhone(model.UserName);
                if (user != null)
                {
                    //var membershipUser = Membership.Provider.GetUser(new Guid(user.RowKey), false);
                    //if (null != membershipUser)
                    //{
                    if (userService.ValidateUser(model.UserName, model.Password))
                        {
                            return Authorize(user);
                        }
                    //}
                }

                ModelState.AddModelError(string.Empty, @"Invalid Email/Phone and/or Password.");
            }

           
            return View(model);


            //if (ModelState.IsValid)
            //{
            //    using (var db = new CDTEntities())
            //    {

            //        var user = db.Users.Any(user => user.Email == model.UserName
            //            && user.Password == model.Password);


            //        //var user = await UserManager.FindAsync(model.UserName, model.Password);
            //        if (user != null)
            //        {
            //            await SignInAsync(user, model.RememberMe);
            //            return RedirectToLocal(returnUrl);
            //        }
            //        else
            //        {
            //            ModelState.AddModelError("", "Invalid username or password.");
            //        }
            //    }

            //}

            //// If we got this far, something failed, redisplay form
            //return View(model);
        }
Example #2
0
        protected void Session_Start()
        {
            if (Context.Request.IsAuthenticated)
            {
                HttpCookie authenticationCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
                if (authenticationCookie != null)
                {
                    FormsAuthenticationTicket authenticationTicket = FormsAuthentication.Decrypt(authenticationCookie.Value);
                    if (authenticationTicket != null && !authenticationTicket.Expired)
                    {
                        var userService = new UserBAL();
                        var user = userService.GetUserByEmailOrPhone(authenticationTicket.Name);
                        if (user != null)
                        {
                            //Session["UserPartitionKey"] = user.PartitionKey;
                           // Session["UserRowKey"] = user.RowKey;
                            Session["UserFirstName"] = user.FirstName;
                            //Session["UserTimezone"] = Convert.ToString(user.TimeZone);

                            //var broadcaster = user.PartitionKey == "BROADCASTER" ? user : UserService.AdminForSubscriber(user.PartitionKey, user.RowKey);

                           // if (null != broadcaster)
                            {
                                Session["IsAdmin"] = true;
                                //Session["ShowAdMenu"] = broadcaster.EnableCampaigns;
                                //Session["ShowGroupMenu"] = broadcaster.EnableGroups;

                                //Session["BroadcasterPartitionKey"] = broadcaster.PartitionKey;
                                //Session["BroadcasterRowKey"] = broadcaster.RowKey;
                                //Session["BroadcasterName"] = broadcaster.DisplayName;
                                //Session["BroadcasterTimezone"] = Convert.ToString(broadcaster.TimeZone);
                                //Session["GroupName"] = broadcaster.ShortName;
                            }
                        }
                    }
                }
            }
        }