Exemplo n.º 1
0
        public ActionResult Login(SignInUpModel model, string returnUrl)
        {
            if (WebSecurity.IsAuthenticated)
            {
                return(RedirectToLocal(returnUrl));
            }

            ViewBag.ReturnUrl = returnUrl;

            ModelState.Remove("SEmail");
            ModelState.Remove("SPassword");
            ModelState.Remove("SName");
            //string username = servicesManager.AccountService.GetUsernameByEmail(model.Email);
            if (ModelState.IsValid && WebSecurity.Login(model.Email, model.Password, persistCookie: model.RememberMe))
            {
                return(RedirectToLocal(returnUrl));
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            model.InvalidPassword = true;
            model.Password        = "******";
            model.tab             = 0;

            ViewBag.Countries = servicesManager.CountryFrontService.GetOnlineCountries();
            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult Register(SignInUpModel model, IEnumerable <HttpPostedFileBase> image_file, string returnUrl)
        {
            if (WebSecurity.IsAuthenticated)
            {
                return(RedirectToLocal(returnUrl));
            }

            ViewBag.ReturnUrl = returnUrl;

            ModelState.Remove("Email");
            ModelState.Remove("Password");
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    int user_id = servicesManager.AccountService.IsEmailExist(model.SEmail);
                    if (user_id > 0)
                    {
                        ModelState.AddModelError("SEmail", "Email already exists. Please enter a different email.");
                    }
                    else
                    {
                        WebSecurity.CreateUserAndAccount(model.SEmail, model.SPassword, new { Name = model.SName, RegistrationDate = DateTime.Now, Gender = model.Gender, CountryId = model.Country, IsApproved = true, IsLockedOut = false, LastLoginDate = DateTime.Now, LastPasswordChangedDate = DateTime.Now, LastLockoutDate = DateTime.Now });
                        WebSecurity.Login(model.SEmail, model.SPassword);
                        Roles.AddUserToRole(model.SEmail, "Member");

                        dataManager     = new DataAccessManager();
                        servicesManager = new ServicesManager(dataManager);
                        //subscribe user
                        if (model.Subscribe)
                        {
                            servicesManager.AccountService.Subscribe(servicesManager.AccountService.GetUserIdByName(model.SName), model.SEmail, 1);
                        }

                        //upload user image
                        servicesManager.AccountService.AddUserImages(servicesManager.AccountService.GetUserIdByName(model.SName), image_file);

                        return(RedirectToLocal(returnUrl));
                    }
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            model.tab = 1;
            // If we got this far, something failed, redisplay form
            ViewBag.Countries = servicesManager.CountryFrontService.GetOnlineCountries();
            return(View("Login", model));
        }