public BoardController(
     ForumServices forumServices,
     SearchServices searchServices,
     ThreadServices threadServices,
     PostServices postServices,
     PollServices pollServices,
     GlobalServices globalServices,
     IRepository<OnlineUser> onlineUserRepository,
     IRepository<OnlineGuest> onlineGuestRepository,
     IRepository<User> userRepository,
     UserServices usersServices,
     RoleServices roleServices,
     MessageServices messageServices,
     PermissionServices permissionServices,
     FileServices fileServices,
     User currentUser,
     Theme currentTheme)
 {
     _forumServices = forumServices;
     _searchServices = searchServices;
     _threadServices = threadServices;
     _postServices = postServices;
     _pollServices = pollServices;
     _onlineUserRepository = onlineUserRepository;
     _onlineGuestRepository = onlineGuestRepository;
     _userRepository = userRepository;
     _userServices = usersServices;
     _roleServices = roleServices;
     _messageServices = messageServices;
     _permissionServices = permissionServices;
     _fileServices = fileServices;
     _currentUser = currentUser;
     _currentTheme = currentTheme;
     SetTopBreadCrumb("Board");
 }
        public IEnumerable<Category> GetViewableCategories(User currentUser)
        {
            IEnumerable<Category> AllCategories = _categoryRepository.Get();

            return null;
            // return AllCategories.Where(x => x.Forums.Count != 0 && x.Forums.Any(y => y.CanView(currentUser))).OrderBy(x => x.Order);
        }
 public AuthController(
     UserServices userServices, 
     EmailServices emailServices,
     User currentUser)
 {
     _userServices = userServices;
     _emailServices = emailServices;
     _currentUser = currentUser;
 }
Beispiel #4
0
 public static MvcHtmlString UsernameLink(this HtmlHelper html, User user, bool includeRankColor = true)
 {
     if (includeRankColor)
     {
         string colorHex = html.UsernameColor(user).ToString();
         object styleObject = colorHex != string.Empty ? new { style = colorHex } : null;
         return html.ActionLink(user.Username, "UserProfile", "Members", new { UserNameOrID = user.UserID }, styleObject);
     }
     else
         return html.ActionLink(user.Username, "UserProfile", "Members", new { UserNameOrID = user.UserID }, null);
 }
        public Theme GetTheme(User currentUser, string controllerName, string previewTheme)
        {
            Theme theme;

            if (!string.IsNullOrWhiteSpace(previewTheme))
                theme = _themeRepository.Get(int.Parse(previewTheme));
            else if (bool.Parse(SiteConfig.OverrideUserTheme.Value) || currentUser == null || currentUser.UserID == 0 || !currentUser.UserProfile.ThemeID.HasValue)
                theme = _themeRepository.Get(int.Parse(SiteConfig.BoardTheme.Value));
            else
                theme = _themeRepository.Get(currentUser.UserProfile.ThemeID.Value);

            return theme;
        }
        public void NewMessage(Message message, User ToUser, string messageURL)
        {
            ListDictionary replacements = new ListDictionary();

            replacements.Add("{FROMUSERNAME}", message.FromUser.Username);
            replacements.Add("{MESSAGEURL}", messageURL);

            SendEmail(
                ToUser.Email,
                SiteConfig.AutomatedFromEmail.Value,
                "New Message - " + SiteConfig.BoardName.Value,
                EmailTemplates.NewMessage,
                replacements);
        }
        public void EmailChanged(User user)
        {
            ListDictionary replacements = new ListDictionary();

            replacements.Add("{USERNAME}", user.Username);
            replacements.Add("{EMAIL}", user.Email);

            SendEmail(
                user.Email,
                SiteConfig.AutomatedFromEmail.Value,
                "Email changed - " + SiteConfig.BoardName.Value,
                EmailTemplates.EmailChange,
                replacements);
        }
 public MessagesController(
     UserServices userServices,
     MessageServices messageServicess,
     IRepository<Message> messageRepository,
     ParseServices parseServices,
     EmailServices emailServices,
     User currentUser)
 {
     _userServices = userServices;
     _messageServices = messageServicess;
     _parseServices = parseServices;
     _emailServices = emailServices;
     _currentUser = currentUser;
     SetCrumbs("User CP", "User CP");
 }
 public RolesController(
     RoleServices roleServices,
     IRepository<Role> roleRepository,
     IRepository<InRole> inRoleRepository,
     IRepository<User> userRepository,
     IRepository<Rank> rankRepository,
     User currentUser)
 {
     _roleServices = roleServices;
     _roleRepository = roleRepository;
     _inRoleRepository = inRoleRepository;
     _userRepository = userRepository;
     _rankRepository = rankRepository;
     _currentUser = currentUser;
     SetCrumb("Roles");
 }
Beispiel #10
0
        public static IHtmlString UsernameColor(this HtmlHelper html, User user)
        {
            if (user == null || user.UserID == 0)
                return new HtmlString(string.Empty);

            var kernel = ((IHaveKernel)html.ViewContext.RequestContext.HttpContext.ApplicationInstance).Kernel;
            var RoleRep = kernel.Get<IRepository<Role>>();

            if (user.UserProfile.DefaultRole.HasValue)
            {
                Role role = RoleRep.Get(user.UserProfile.DefaultRole.Value);
                return new HtmlString(role.Rank.Color);
            }
            else
                return new HtmlString(string.Empty);
        }
        public void OnlineUserRoutine(User user, string ipAddress)
        {
            bool IsAuthenticated = user != null;

            if (IsAuthenticated)
            {
                OnlineUser onlineUser = _onlineUserRepository.Get(user.UserID);
                OnlineGuest onlineGuest = _onlineGuestRepository.First(item => item.IP.Equals(ipAddress));

                if (onlineGuest != null)
                    _onlineGuestRepository.Delete(onlineGuest.OnlineGuestID);

                if (onlineUser == null)
                {
                    _onlineUserRepository.Add(new OnlineUser
                    {
                        UserID = user.UserID,
                        Date = DateTime.UtcNow,
                    }
                    );
                }
                else
                {
                    onlineUser.Date = DateTime.UtcNow;
                    _onlineUserRepository.Update(onlineUser);
                }
            }
            else
            {
                OnlineGuest onlineGuest = _onlineGuestRepository.First(item => item.IP.Equals(ipAddress));
                if (onlineGuest == null)
                {
                    _onlineGuestRepository.Add(new OnlineGuest
                    {
                        IP = ipAddress,
                        Date = DateTime.UtcNow
                    });
                }
                else
                {
                    onlineGuest.Date = DateTime.UtcNow;
                    _onlineGuestRepository.Update(onlineGuest);
                }
            }

            _unitOfWork.Commit();
        }
 public UserController(
     ThemeServices themes,
     UserServices users,
     ParseServices parseServices,
     MessageServices messageServices,
     EmailServices emailServices,
     FileServices fileServices,
     RoleServices roleServices,
     User currentUser)
 {
     _themeServices = themes;
     _userServices = users;
     _parseServices = parseServices;
     _messageServices = messageServices;
     _emailServices = emailServices;
     _fileServices = fileServices;
     _roleServices = roleServices;
     _currentUser = currentUser;
     SetTopBreadCrumb("User CP");
     SetBreadCrumb("User CP");
 }
 public PostController(
     IRepository<Smiley> smileyRepository, 
     ForumServices forumServices,
     PostServices postServices,
     ThreadServices threadServices,
     FileServices fileServices,
     PollServices pollServices,
     EmailServices emailServices,
     PermissionServices permissionServices,
     ParseServices parseServices,
     User currentUser)
 {
     _smileyRepository = smileyRepository;
     _forumServices = forumServices;
     _postServices = postServices;
     _threadServices = threadServices;
     _fileServices = fileServices;
     _pollServices = pollServices;
     _emailServices = emailServices;
     _permissionServices = permissionServices;
     _parseServices = parseServices;
     _currentUser = currentUser;
 }
Beispiel #14
0
        public static IHtmlString UserRank(this HtmlHelper html, User user)
        {
            Rank rank;

            var kernel = ((IHaveKernel)html.ViewContext.RequestContext.HttpContext.ApplicationInstance).Kernel;
            var rolesRepository = kernel.Get<IRepository<Role>>();
            var rankRepository = kernel.Get<IRepository<Rank>>();

            if (user.UserProfile.DefaultRole.HasValue)
            {
                Role role = rolesRepository.Get(user.UserProfile.DefaultRole.Value);
                rank = role.Rank;
            }
            else
                rank = rankRepository.Where(item => item.PostCount - user.Posts.Count < 0).OrderByDescending(item => item.PostCount).FirstOrDefault();

            if (rank == null)
                return null;

            TagBuilder title = new TagBuilder("span");
            title.MergeAttribute("style", string.Format("color:{0}", rank.Color));
            title.AddCssClass("title");

            if (string.IsNullOrWhiteSpace(rank.Image))
                return new HtmlString(title.ToString());

            UrlHelper url = new UrlHelper(html.ViewContext.RequestContext);

            string src = string.Format("~/Images/Ranks/{0}", rank.Image);

            TagBuilder image = new TagBuilder("img");
            image.MergeAttribute("src", url.Content(src));

            HtmlString output = new HtmlString(title.ToString() + image.ToString(TagRenderMode.SelfClosing));

            return output;
        }
        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            base.Initialize(requestContext);

            if (!Settings.IsInstalled)
                return;

            var userServices = ServiceLocator.Get<UserServices>();
            var themeServices = ServiceLocator.Get<ThemeServices>();
            var globalServices = ServiceLocator.Get<GlobalServices>();

            bool isAuthenticated = requestContext.HttpContext.User.Identity.IsAuthenticated;
            string controllerName = requestContext.RouteData.GetRequiredString("controller");
            string ipAddress = requestContext.HttpContext.Request.UserHostAddress;

            var timeZoneOffset = SiteConfig.TimeOffset.ToInt();
            ViewData[ViewDataKeys.TimeZoneOffset] = timeZoneOffset;

            if (isAuthenticated)
            {
                this.CurrentUser = userServices.GetUser(int.Parse(requestContext.HttpContext.User.Identity.Name));
                if (CurrentUser == null)
                {
                    this.CurrentUser = new Data.User { UserID = 0 };
                    FormsAuthentication.SignOut();
                    isAuthenticated = false;
                }
                else
                {
                    ViewData[ViewDataKeys.CurrentUser] = CurrentUser;
                }
            }
            else
                this.CurrentUser = new Data.User { UserID = 0 };

            string previewTheme = (string)requestContext.HttpContext.Session["ptheme"];

            if (requestContext.RouteData.GetAreaName() == "Admin")
                CurrentTheme = themeServices.GetAdminTheme();
            else
                CurrentTheme = themeServices.GetTheme(CurrentUser, controllerName, previewTheme);

            requestContext.HttpContext.Items[HttpContextItemKeys.ThemeFolder] = CurrentTheme.FolderName;
        }
 public bool CanLock(User user)
 {
     if (user == null)
         return false;
     return _roleServices.UserHasSpecialPermissions(user.UserID, SpecialPermissionValue.Administrator, SpecialPermissionValue.Moderator);
 }
Beispiel #17
0
 public bool ValidatePassword(User user, string password)
 {
     string hashedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(password + user.PasswordSalt, "MD5");
     return user.Password == hashedPassword;
 }
Beispiel #18
0
        public User Register(string username, string password, string email)
        {
            string activationType = SiteConfig.AccountActivation.Value;
            string salt = Randoms.CreateSalt() + DateTime.UtcNow.ToString();
            string hashedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(password + salt, "MD5");

            var user = new User()
            {
                Password = hashedPassword,
                PasswordSalt = salt,
                RegisterDate = DateTime.UtcNow,
                RegisterIP = HttpContext.Current.Request.UserHostAddress,
                ActivationCode = activationType == "None" ? string.Empty : Randoms.CleanGUID(),
                Status = false,
                LastLoginIP = null,
                Username = username,
                UsernameLower = username.ToLower(),
                LastLoginDate = DateTime.UtcNow,
                LastLogoutDate = DateTime.UtcNow,
                LastPostDate = DateTime.UtcNow,
                Email = email
            };

            user.UserProfile = new UserProfile()
            {
                AlwaysShowSignature = true,
                AlwaysSubscribeToThread = true,
                AvatarType = "None",
                ThemeID = SiteConfig.BoardTheme.ToInt()
            };

            var inRole = new InRole()
            {
                UserID = user.UserID,
                RoleID = SiteConfig.RegistrationRole.IntValue()
            };
            user.InRoles.Add(inRole);

            _userRepository.Add(user);
            _unitOfWork.Commit();
            return user;
        }
Beispiel #19
0
        public void LoginRoutine(User user, string ipAddress)
        {
            user.LastLoginDate = DateTime.UtcNow;
            user.LastLoginIP = ipAddress;

            OnlineGuest guest = _onlineGuestRepository.First(item => item.IP.Equals(ipAddress));

            if (guest != null)
                _onlineGuestRepository.Delete(guest);

            OnlineUser oUser = _onlineUserRepository.Get(user.UserID);
            if (oUser == null)
            {
                _onlineUserRepository.Add(new OnlineUser
                {
                    Date = DateTime.UtcNow,
                    UserID = user.UserID
                });
            }
            else
            {
                oUser.Date = DateTime.UtcNow;
                _onlineUserRepository.Update(oUser);
            }
            IEnumerable<ThreadViewStamp> views = _threadViewStampRepository.Where(item => item.UserID.Equals(user.UserID));
            _threadViewStampRepository.Delete(views);
            _unitOfWork.Commit();
        }
        public void PasswordResetRequest(User user, string ResetURL)
        {
            ListDictionary replacements = new ListDictionary();

            replacements.Add("{USERNAME}", user.Username);
            replacements.Add("{RESET_URL}", ResetURL);

            SendEmail(
                user.Email,
                SiteConfig.AutomatedFromEmail.Value,
                "Password Reset Request - " + SiteConfig.BoardName.Value,
                EmailTemplates.PasswordResetRequest,
                replacements);
        }
        public void ResendActivationCode(User user, string confirm_url)
        {
            ListDictionary replacements = new ListDictionary();

            replacements.Add("{USERNAME}", user.Username);
            replacements.Add("{CONFIRM_URL}", confirm_url);

            SendEmail(
                user.Email,
                SiteConfig.AutomatedFromEmail.Value,
                "Account Activation Required - " + SiteConfig.BoardName.Value,
                EmailTemplates.ResendActivationCode,
                replacements);
        }
        public void PasswordChanged(User user, string NewPassword)
        {
            ListDictionary replacements = new ListDictionary();

            replacements.Add("{USERNAME}", user.Username);
            replacements.Add("{USERPASSWORD}", NewPassword);

            SendEmail(
                user.Email,
                SiteConfig.AutomatedFromEmail.Value,
                "Password Changed - " + SiteConfig.BoardName,
                EmailTemplates.PasswordChange,
                replacements);
        }
        public void WelcomeEmail(User user)
        {
            ListDictionary replacements = new ListDictionary();

            replacements.Add("{USERNAME}", user.Username);

            SendEmail(
                user.Email,
                SiteConfig.AutomatedFromEmail.Value,
                "Welcome - " + SiteConfig.BoardName,
                EmailTemplates.Welcome,
                replacements);
        }