コード例 #1
0
ファイル: Global.asax.cs プロジェクト: ghostnguyen/oams
        protected void Application_Start()
        {
            RoleRepository repo = new RoleRepository();
            repo.InitRole();

            ControllerActionRepository actionAuthorizationRepo = new ControllerActionRepository();
            actionAuthorizationRepo.UpdateActionList();

            AreaRegistration.RegisterAllAreas();
            RegisterRoutes(RouteTable.Routes);
        }
コード例 #2
0
ファイル: AccountRepository.cs プロジェクト: ghostnguyen/oams
        public List<UserModel> GetAll()
        {
            RoleRepository roleRepo = new RoleRepository();
            List<UserModel> l = new List<UserModel>();
            foreach (MembershipUser item in Membership.GetAllUsers())
            {
                UserModel user = new UserModel();
                user.Username = item.UserName;
                user.RolesList = roleRepo.GetRolesList(item.UserName);

                l.Add(user);
            }

            return l;
        }
コード例 #3
0
ファイル: AccountController.cs プロジェクト: ghostnguyen/oams
        public ActionResult Edit(string id, string[] RoleList)
        {
            RoleRepository roleRepo = new RoleRepository();
            roleRepo.SetRoles(id, RoleList);

            return View(new UserModel() { Username = id });
        }
コード例 #4
0
ファイル: AccountController.cs プロジェクト: ghostnguyen/oams
        public ActionResult UpdateControllerAction()
        {
            RoleRepository repo = new RoleRepository();
            repo.InitRole();

            ControllerActionRepository actionAuthorizationRepo = new ControllerActionRepository();
            actionAuthorizationRepo.UpdateActionList();

            return RedirectToAction("Index", "Home");
        }
コード例 #5
0
ファイル: AccountController.cs プロジェクト: ghostnguyen/oams
        public ActionResult OpenIdLogOn(string returnUrl)
        {
            if (OAMSSetting.ByPassLogin && !Request.IsAuthenticated)
            {
                string username = repo.Create_ByPassLogin();
                this.IssueAuthTicket(username, true);

                if (string.IsNullOrEmpty(returnUrl))
                    returnUrl = "~/";

                return Redirect(returnUrl);
            }
            else
            {
                var openid = new OpenIdRelyingParty();
                var response = openid.GetResponse();
                if (response == null)  // Initial operation
                {
                    // Step 1 - Send the request to the OpenId provider server
                    string openid_identifier = "https://www.google.com/accounts/o8/id";
                    //Identifier id;

                    //if (Identifier.TryParse(Request.Form["openid_identifier"], out id))
                    //{
                    //    try
                    //    {
                    //        var req = openid.CreateRequest(Request.Form["openid_identifier"]);
                    //        return req.RedirectingResponse.AsActionResult();
                    //    }
                    //    catch (ProtocolException ex)
                    //    {
                    //        // display error by showing original LogOn view
                    //        //this.ErrorDisplay.ShowError("Unable to authenticate: " + ex.Message);
                    //        return View("Logon");
                    //    }
                    //}
                    //else
                    //{
                    //    // display error by showing original LogOn view
                    //    //this.ErrorDisplay.ShowError("Invalid identifier");
                    //    //return View("LogOn", this.ViewModel);
                    //    return View("LogOn");
                    //}

                    try
                    {
                        var req = openid.CreateRequest(openid_identifier);

                        var fetch = new FetchRequest();
                        fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
                        fetch.Attributes.AddRequired(WellKnownAttributes.Name.First);
                        fetch.Attributes.AddRequired(WellKnownAttributes.Name.Last);

                        req.AddExtension(fetch);

                        return req.RedirectingResponse.AsActionResult();
                    }
                    catch (ProtocolException)
                    {
                        // display error by showing original LogOn view
                        //this.ErrorDisplay.ShowError("Unable to authenticate: " + ex.Message);
                        return View("Logon");
                    }

                }
                else  // OpenId redirection callback
                {
                    // Step 2: OpenID Provider sending assertion response
                    switch (response.Status)
                    {
                        case AuthenticationStatus.Authenticated:
                            string identifier = response.ClaimedIdentifier;

                            var fetch = response.GetExtension<FetchResponse>();
                            string email = string.Empty;
                            string fullname = string.Empty;
                            if (fetch != null)
                            {
                                email = fetch.GetAttributeValue(WellKnownAttributes.Contact.Email);
                                fullname = fetch.GetAttributeValue(WellKnownAttributes.Name.FullName);
                            }

                            if (repo.Exist(email, identifier))
                            {

                            }
                            else
                            {
                                repo.Create(email, identifier);
                            }

                            // OpenId lookup fails - Id doesn't exist for login - login first
                            //if (busUser.ValidateUserOpenIdAndLoad(identifier) == null)
                            //{
                            //    //this.ErrorDisplay.HtmlEncodeMessage = false;
                            //    //this.ErrorDisplay.ShowError(busUser.ErrorMessage +
                            //    //        "Please <a href='" + WebUtils.ResolveUrl("~/Account/Register") +
                            //    //        "'>register</a> to create a new account or <a href='" +
                            //    //        WebUtils.ResolveUrl("~/Account/Register") +
                            //    //        "'>associate</a> an existing account with your OpenId");

                            //    //return View("LogOn", this.ViewModel);
                            //    return View("LogOn");
                            //}

                            // Capture user information for AuthTicket
                            // and issue Forms Auth token
                            //UserState userState = new UserState()
                            //{
                            //    Email = busUser.Entity.Email,
                            //    Name = busUser.Entity.Name,
                            //    UserId = busUser.Entity.Id,
                            //    IsAdmin = busUser.Entity.IsAdmin
                            //};
                            //this.IssueAuthTicket(userState, true);

                            this.IssueAuthTicket(email, true);

                            RoleRepository roleRepo = new RoleRepository();
                            if (roleRepo.GetRolesList(email).Count() == 0)
                            {
                                returnUrl = "~/Account/Guest";
                            }

                            if (string.IsNullOrEmpty(returnUrl))
                                returnUrl = "~/";

                            return Redirect(returnUrl);

                        case AuthenticationStatus.Canceled:
                            //this.ErrorDisplay.ShowMessage("Canceled at provider");
                            //return View("LogOn", this.ViewModel);
                            return View("LogOn");
                        case AuthenticationStatus.Failed:
                            //this.ErrorDisplay.ShowError(response.Exception.Message);
                            //return View("LogOn", this.ViewModel);
                            return View("LogOn");
                    }
                }
            }
            return new EmptyResult();
        }
コード例 #6
0
ファイル: AccountController.cs プロジェクト: ghostnguyen/oams
        public ActionResult EditAccountInRole(string rolename, string[] UserList)
        {
            RoleRepository roleRepo = new RoleRepository();
            roleRepo.SetUsersToRole(rolename, UserList);

            return View((object)rolename);
        }