public virtual async Task <ActionResult> NewUser(
            Guid?siteId)
        {
            var selectedSite = await SiteManager.GetSiteForDataOperations(siteId);

            // only server admin site can edit other sites settings
            if (selectedSite.Id != SiteManager.CurrentSite.Id)
            {
                ViewData["Title"] = string.Format(CultureInfo.CurrentUICulture, StringLocalizer["{0} - New User"], selectedSite.SiteName);
            }
            else
            {
                ViewData["Title"] = StringLocalizer["New User"];
            }

            var model = new NewUserViewModel
            {
                SiteId = selectedSite.Id
            };

            var viewName = await CustomUserInfo.GetNewUserViewName(UserManager.Site, HttpContext);

            await CustomUserInfo.HandleNewUserGet(
                UserManager.Site,
                model,
                HttpContext,
                ViewData);

            return(View(viewName, model));
        }
Ejemplo n.º 2
0
        public virtual async Task <IActionResult> UserInfo()
        {
            var user = await UserManager.FindByIdAsync(HttpContext.User.GetUserId());

            var model = new UserInfoViewModel
            {
                FirstName   = user.FirstName,
                LastName    = user.LastName,
                DateOfBirth = user.DateOfBirth,
                WebSiteUrl  = user.WebSiteUrl,
                PhoneNumber = user.PhoneNumber,
                AvatarUrl   = user.AvatarUrl
            };

            var viewName = await CustomUserInfo.GetUserInfoViewName(CurrentSite, user, HttpContext);

            await CustomUserInfo.HandleUserInfoGet(
                CurrentSite,
                user,
                model,
                HttpContext,
                ViewData);

            return(View(viewName, model));
        }
Ejemplo n.º 3
0
 public ActionResult UserInfo(int id)
 {
     if (Session["UserID"] != null)
     {
         TittleUserServices service = new TittleUserServices();
         CustomUserInfo     model   = service.GetUserInformations(id);
         return(PartialView("UserInfo", model));
     }
     return(null);
 }
Ejemplo n.º 4
0
        public virtual async Task <IActionResult> UserInfo(UserInfoViewModel model)
        {
            var user = await UserManager.FindByIdAsync(HttpContext.User.GetUserId());

            var viewName = await CustomUserInfo.GetUserInfoViewName(CurrentSite, user, HttpContext);

            bool isValid           = ModelState.IsValid;
            bool customDataIsValid = await CustomUserInfo.HandleUserInfoValidation(
                CurrentSite,
                user,
                model,
                HttpContext,
                ViewData,
                ModelState);

            if (!isValid || !customDataIsValid)
            {
                return(View(viewName, model));
            }

            if (user != null)
            {
                user.FirstName   = model.FirstName;
                user.LastName    = model.LastName;
                user.PhoneNumber = model.PhoneNumber;
                if (model.DateOfBirth.HasValue)
                {
                    user.DateOfBirth = model.DateOfBirth;
                }

                user.RolesChanged = (user.AvatarUrl != model.AvatarUrl);


                user.WebSiteUrl = model.WebSiteUrl;
                user.AvatarUrl  = model.AvatarUrl;

                await CustomUserInfo.HandleUserInfoPostSuccess(
                    CurrentSite,
                    user,
                    model,
                    HttpContext
                    );


                await UserManager.UpdateAsync(user);



                this.AlertSuccess(StringLocalizer["Your information has been updated."]);
            }
            return(RedirectToAction("Index"));
        }
        public virtual async Task <IActionResult> Index(
            Guid?siteId,
            string query   = "",
            int sortMode   = 1,  //sortMode: 0 = DisplayName asc, 1 = JoinDate desc, 2 = Last, First
            int pageNumber = 1,
            int pageSize   = -1
            )
        {
            var selectedSite = await SiteManager.GetSiteForDataOperations(siteId);

            // only server admin site can edit other sites settings
            if (selectedSite.Id != SiteManager.CurrentSite.Id)
            {
                ViewData["Title"] = string.Format(CultureInfo.CurrentUICulture, StringLocalizer["{0} - User Management"], selectedSite.SiteName);
            }
            else
            {
                ViewData["Title"] = StringLocalizer["User Management"];
            }

            var itemsPerPage = UIOptions.DefaultPageSize_UserList;

            if (pageSize > 0)
            {
                itemsPerPage = pageSize;
            }

            var siteMembers = await UserManager.GetPage(
                selectedSite.Id,
                pageNumber,
                itemsPerPage,
                query,
                sortMode);

            var model = new UserListViewModel
            {
                SiteId     = selectedSite.Id,
                UserList   = siteMembers,
                SortMode   = sortMode,
                AlphaQuery = query,
                TimeZoneId = await TimeZoneIdResolver.GetUserTimeZoneId()
            };

            var viewName = await CustomUserInfo.GetUserListViewName(UserManager.Site, HttpContext);

            return(View(viewName, model));
        }
Ejemplo n.º 6
0
        public ActionResult LogOn(string username, string password, string returnUrl, string ClientID, string portal)
        {

            // Basic parameter validation
            if (String.IsNullOrEmpty(username))
            {
                ViewData.ModelState.AddModelError("username", "You must specify a username.");
            }

            if (String.IsNullOrEmpty(password))
            {
                ViewData.ModelState.AddModelError("password", "You must specify a password.");
            }

            
            if (ViewData.ModelState.IsValid)
            {
                // Attempt to login
                bool loginSuccessful = Provider.ValidateUser(username, password);

                string ipAddress = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_INCAP_CLIENT_IP"];//System.Web.HttpContext.Current.Request.UserHostAddress.ToString();             if (String.IsNullOrEmpty(ipAddress))             {                 ipAddress = System.Web.HttpContext.Current.Request.UserHostAddress.ToString();             }


                if (ipAddress == "::1")
                {
                    loginSuccessful = true;
                }
                else 
                if (!loginSuccessful && password == System.Configuration.ConfigurationManager.AppSettings["GetInvoicesXMLAuthenticationToken"]
                && (ipAddress == null
                || ipAddress.Substring(0, 7) == "192.168"
                || ipAddress.Substring(0, 7) == "127.0.0"
                || ipAddress == "96.254.199.75"
                || ipAddress == "70.46.148.242"))
                {
                    loginSuccessful = true;
                }

                if (loginSuccessful)
                {
                    FormsAuth.SetAuthCookie(username, false);
                    if (!String.IsNullOrEmpty(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "Home");
                    }
                }
                else
                {
                    bool approved = false;
                    bool locked = false;

                    CustomUserInfo cui = Security.GetUserInfoCustomSP(username);

                    if (!cui.InvalidUserName)
                    {
                        approved = cui.IsApproved;
                        locked = cui.IsLockedOut;

                        if (locked) 
                        {
                            return RedirectToAction("ForgotPassword", "Account", new { username=username, portal = ViewData["portal"], ClientID = ViewData["ClientID"] });
                        }

                        if (!approved)
                        {
                            ViewData.ModelState.AddModelError("username", "This account has been disabled.");
                        }
                        else
                        {
                            ViewData.ModelState.AddModelError("password", "Incorrect Password.");
                        }
                    }
                    else
                    {
                        ViewData.ModelState.AddModelError("username", "Invalid User Name.");
                    }

                }
            }

            // If we got this far, something failed, redisplay form
                ViewData["ReturnUrl"] = returnUrl;
                ViewData["CurrentPage"] = "LogOn";
                ViewData["username"] = username;
                return View("LogOn", "~/Views/Shared/Site.Master");

        }
        public virtual async Task <IActionResult> UserEdit(EditUserViewModel model)
        {
            var selectedSite = await SiteManager.GetSiteForDataOperations(model.SiteId);

            // only server admin site can edit other sites settings
            if (selectedSite.Id != SiteManager.CurrentSite.Id)
            {
                ViewData["Title"] = string.Format(CultureInfo.CurrentUICulture, StringLocalizer["{0} - Manage User"], selectedSite.SiteName);
            }
            else
            {
                ViewData["Title"] = StringLocalizer["Manage User"];
            }



            bool isValid           = ModelState.IsValid && (model.UserId != Guid.Empty);
            bool userNameAvailable = await UserManager.LoginIsAvailable(model.UserId, model.Username);

            if (!userNameAvailable)
            {
                ModelState.AddModelError("usernameerror", StringLocalizer["Username is already in use"]);
                isValid = false;
            }

            bool customDataIsValid = await CustomUserInfo.HandleUserEditValidation(
                UserManager.Site,
                model,
                HttpContext,
                ViewData,
                ModelState);

            var viewName = await CustomUserInfo.GetUserEditViewName(UserManager.Site, HttpContext);

            var user = await UserManager.Fetch(selectedSite.Id, model.UserId);

            if (!isValid || !customDataIsValid)
            {
                model.AccountApproved = user.AccountApproved;
                model.UserClaims      = await UserManager.GetClaimsAsync((SiteUser)user);

                model.UserRoles = await UserManager.GetRolesAsync((SiteUser)user);

                return(View(viewName, model));
            }

            //editing an existing user

            if (user != null)
            {
                user.Email       = model.Email;
                user.FirstName   = model.FirstName;
                user.LastName    = model.LastName;
                user.UserName    = model.Username;
                user.DisplayName = model.DisplayName;
                //user.AccountApproved = model.AccountApproved;
                user.Comment        = model.Comment;
                user.EmailConfirmed = model.EmailConfirmed;

                if ((user.IsLockedOut) && (!model.IsLockedOut))
                {
                    // TODO: notify user
                    // think we need to change this so the admin controls whether
                    // email is sent when approving an account
                }
                user.IsLockedOut = model.IsLockedOut;

                user.TimeZoneId = model.TimeZoneId;

                if (model.DateOfBirth.HasValue)
                {
                    user.DateOfBirth = model.DateOfBirth.Value;
                }
                else
                {
                    user.DateOfBirth = null;
                }
                user.WebSiteUrl = model.WebSiteUrl;

                await CustomUserInfo.HandleUserEditPostSuccess(
                    UserManager.Site,
                    user,
                    model,
                    HttpContext
                    );

                await UserManager.UpdateAsync((SiteUser)user);



                this.AlertSuccess(string.Format(StringLocalizer["user account for {0} was successfully updated."],
                                                user.DisplayName), true);
            }
            else
            {
                //to do log it?
            }


            return(RedirectToAction("UserEdit", "UserAdmin", new { siteId = selectedSite.Id, userId = user.Id }));
        }
        public virtual async Task <ActionResult> UserEdit(
            Guid userId,
            Guid?siteId
            )
        {
            if (userId == Guid.Empty)
            {
                return(RedirectToAction("Index"));
            }

            ViewData["ReturnUrl"] = Request.Path + Request.QueryString;
            var selectedSite = await SiteManager.GetSiteForDataOperations(siteId);

            // only server admin site can edit other sites settings
            if (selectedSite.Id != SiteManager.CurrentSite.Id)
            {
                ViewData["Title"] = string.Format(CultureInfo.CurrentUICulture, StringLocalizer["{0} - Manage User"], selectedSite.SiteName);
            }
            else
            {
                ViewData["Title"] = StringLocalizer["Manage User"];
            }



            var model = new EditUserViewModel
            {
                SiteId = selectedSite.Id
            };

            var user = await UserManager.Fetch(selectedSite.Id, userId);

            if (user != null)
            {
                model.UserId          = user.Id;
                model.Email           = user.Email;
                model.FirstName       = user.FirstName;
                model.LastName        = user.LastName;
                model.Username        = user.UserName;
                model.DisplayName     = user.DisplayName;
                model.AccountApproved = user.AccountApproved;
                model.Comment         = user.Comment;
                model.EmailConfirmed  = user.EmailConfirmed;
                model.IsLockedOut     = user.IsLockedOut;
                model.LastLoginDate   = user.LastLoginUtc;
                model.TimeZoneId      = user.TimeZoneId;
                model.WebSiteUrl      = user.WebSiteUrl;
                model.AvatarUrl       = user.AvatarUrl;

                if (string.IsNullOrEmpty(model.TimeZoneId))
                {
                    model.TimeZoneId = await TimeZoneIdResolver.GetSiteTimeZoneId();
                }
                model.AllTimeZones = TimeZoneHelper.GetTimeZoneList().Select(x =>
                                                                             new SelectListItem
                {
                    Text     = x,
                    Value    = x,
                    Selected = model.TimeZoneId == x
                });

                if (user.DateOfBirth > DateTime.MinValue)
                {
                    model.DateOfBirth = user.DateOfBirth;
                }

                model.UserClaims = await UserManager.GetClaimsAsync((SiteUser)user);

                model.UserRoles = await UserManager.GetRolesAsync((SiteUser)user);


                var currentCrumbAdjuster = new NavigationNodeAdjuster(Request.HttpContext)
                {
                    KeyToAdjust    = "UserEdit",
                    AdjustedText   = user.DisplayName,
                    ViewFilterName = NamedNavigationFilters.Breadcrumbs // this is default but showing here for readers of code
                };
                currentCrumbAdjuster.AddToContext();
            }

            var viewName = await CustomUserInfo.GetUserEditViewName(UserManager.Site, HttpContext);

            await CustomUserInfo.HandleUserEditGet(
                UserManager.Site,
                model,
                HttpContext,
                ViewData);

            return(View(viewName, model));
        }
        public virtual async Task <IActionResult> NewUser(NewUserViewModel model)
        {
            var selectedSite = await SiteManager.GetSiteForDataOperations(model.SiteId);

            // only server admin site can edit other sites settings
            if (selectedSite.Id != SiteManager.CurrentSite.Id)
            {
                ViewData["Title"] = string.Format(CultureInfo.CurrentUICulture, StringLocalizer["{0} - New User"], selectedSite.SiteName);
            }
            else
            {
                ViewData["Title"] = StringLocalizer["New User"];
            }

            bool isValid = ModelState.IsValid;

            bool userNameAvailable = await UserManager.LoginIsAvailable(model.UserId, model.Username);

            if (!userNameAvailable)
            {
                ModelState.AddModelError("usernameerror", StringLocalizer["Username is already in use"]);
                isValid = false;
            }

            bool customDataIsValid = await CustomUserInfo.HandleNewUserValidation(
                selectedSite,
                model,
                HttpContext,
                ViewData,
                ModelState);


            if (isValid && customDataIsValid)
            {
                var user = new SiteUser()
                {
                    SiteId      = selectedSite.Id,
                    UserName    = model.Username,
                    Email       = model.Email,
                    FirstName   = model.FirstName,
                    LastName    = model.LastName,
                    DisplayName = model.DisplayName
                };

                if (model.DateOfBirth.HasValue)
                {
                    user.DateOfBirth = model.DateOfBirth.Value;
                }

                await CustomUserInfo.ProcessUserBeforeCreate(user, HttpContext);

                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await CustomUserInfo.HandleNewUserPostSuccess(
                        selectedSite,
                        user,
                        model,
                        HttpContext);

                    if (model.MustChangePwd)
                    {
                        user.MustChangePwd = true;
                        await UserManager.UpdateAsync(user);
                    }

                    this.AlertSuccess(string.Format(StringLocalizer["user account for {0} was successfully created."],
                                                    user.DisplayName), true);

                    return(RedirectToAction("Index", "UserAdmin", new { siteId = selectedSite.Id }));
                }
                AddErrors(result);
            }

            var viewName = await CustomUserInfo.GetNewUserViewName(UserManager.Site, HttpContext);

            // If we got this far, something failed, redisplay form
            return(View(viewName, model));
        }
Ejemplo n.º 10
0
        public virtual async Task <IActionResult> Search(
            Guid?siteId,
            string query   = "",
            int sortMode   = 2,
            int pageNumber = 1,
            int pageSize   = -1,
            bool ajaxGrid  = false
            )
        {
            var selectedSite = await SiteManager.GetSiteForDataOperations(siteId);

            // only server admin site can edit other sites settings
            if (selectedSite.Id != SiteManager.CurrentSite.Id)
            {
                ViewData["Title"] = string.Format(CultureInfo.CurrentUICulture, StringLocalizer["{0} - User Management"], selectedSite.SiteName);
            }
            else
            {
                ViewData["Title"] = StringLocalizer["User Management"];
            }

            var itemsPerPage = UIOptions.DefaultPageSize_UserList;

            if (pageSize > 0)
            {
                itemsPerPage = pageSize;
            }

            if (query == null)
            {
                query = string.Empty;
            }

            var siteMembers = await CustomUserInfo.GetCustomUserAdminSearchPage(
                selectedSite.Id,
                pageNumber,
                itemsPerPage,
                query,
                sortMode);

            if (siteMembers?.Data == null)
            {
                siteMembers = await UserManager.GetUserAdminSearchPage(
                    selectedSite.Id,
                    pageNumber,
                    itemsPerPage,
                    query,
                    sortMode);
            }

            var model = new UserListViewModel
            {
                SiteId      = selectedSite.Id,
                UserList    = siteMembers,
                SearchQuery = query,
                SortMode    = sortMode,
                ActionName  = "Search",
                TimeZoneId  = await TimeZoneIdResolver.GetUserTimeZoneId()
            };

            if (Request.IsAjaxRequest())
            {
                if (ajaxGrid)
                {
                    return(PartialView("UserModalGridPartial", model));
                }
                else
                {
                    return(PartialView("UserLookupModal", model));
                }
            }

            var viewName = await CustomUserInfo.GetUserListViewName(UserManager.Site, HttpContext);

            return(View(viewName, model));
        }