Esempio n. 1
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (Membership.ValidateUser(model.UserName, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);

                    if (ConfigurationManager.AppSettings["ForumAuthenticationEnabled"] == "true")
                    {
                        ForumAuthentication.SetAuthCookie(model.UserName, Request.UserHostAddress, Request.UserAgent, Request.ServerVariables["HTTP_X_FORWARDED_FOR"]);
                    }

                    if (!User.IsInRole("Guest"))
                    {
                        Login             login  = _dataService.GetLoginByUsername(model.UserName);
                        Member            member = login.ClubMember.First();
                        AuthenticatedUser user   = new AuthenticatedUser()
                        {
                            LoginId  = login.Id,
                            Username = model.UserName,
                            FullName = member.FullName,
                            MemberId = member.Id
                        };

                        Session.Add(FlyingClub.Common.ContextVariables.AuthenticatedUser, user);

                        _dataService.UpdateLoggedInDate(login.Id, DateTime.Now);
                    }

                    if ((User.IsInRole("Guest") && Url.IsLocalToHost(returnUrl) && !Url.IsLocalUrl(returnUrl)) || (!User.IsInRole("Guest") && Url.IsLocalToHost(returnUrl)))
                    {
                        return(Redirect(returnUrl));
                    }
                    else if (User.IsInRole("Guest"))
                    {
                        return(Redirect(ConfigurationManager.AppSettings["FrontEndUrl"]));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 2
0
        public ActionResult Create(EditMemberViewModel model)
        {
            if (ModelState.IsValid)
            {
                Member member = model.ConvertToEntity();
                member.MemberSince = DateTime.Now;

                Login login = null;
                if (model.LoginId == 0)
                {
                    login = _dataService.GetLoginByUsername(model.Username);
                }
                else
                {
                    login = _dataService.GetLoginById(model.LoginId);
                }

                if (login == null)
                {
                    ModelState.AddModelError("Username", String.Format("Username '{0}' can not be found in the database", model.Username));
                    model.ClubRoles = _dataService.GetAllRoles();
                    return(View(ViewNames.CreateMember, model));
                }

                member.LoginId = login.Id;

                if (model.MemberRoles != null && model.MemberRoles.Count > 0)
                {
                    List <Role> allRoles = _dataService.GetAllRoles();
                    member.Roles = new List <Role>();
                    foreach (int roleId in model.MemberRoles)
                    {
                        member.Roles.Add(allRoles.FirstOrDefault(r => r.Id == roleId));
                    }
                }

                member.Status = model.Status;
                _dataService.SaveMember(member);
                return(RedirectToAction("Details", new { id = member.Id }));
            }

            model.MemberRoles = new List <int>();
            model.ClubRoles   = _dataService.GetAllRoles();
            return(View(ViewNames.EditMember, model));
        }