コード例 #1
0
        private void CreateAdminUser()
        {
            var    adminId  = Guid.NewGuid();
            string password = this._securityManager.EncodePassword(Resources.DefaultValues.AdministratorPassword);
            var    admin    = new User(adminId, Resources.DefaultValues.AdministratorEmail, Resources.DefaultValues.AdministratorName);

            admin.PreferredCulture = StrixPlatform.DefaultCultureCode;
            this._dataSource.Save(admin);

            var security = new UserSecurity(admin.Id);

            security.Password = password;
            security.Approved = true;
            this._dataSource.Save(security);

            var session = new UserSessionStorage(admin.Id);

            this._dataSource.Save(session);

            var userRole = new UserInRole(this._adminRole, admin.Id, DateTime.Now, null);

            admin.Roles = new List <UserInRole>()
            {
                userRole
            };
        }
コード例 #2
0
        public User Create(string name, string email, string preferredCulture, string password, bool isApproved, bool acceptedTerms, string registrationComment)
        {
            if (string.IsNullOrWhiteSpace(email))
            {
                throw new ArgumentNullException("email");
            }

            this.CheckEmailAvailable(email);
            User user = this._dataSource.Query <User>().FirstOrDefault(u => u.Email.ToLower() == email.ToLower());

            if (user == null)
            {
                CheckPassword(password);
                var encodedPassword = this._securityManager.EncodePassword(password);

                user = new User(Guid.NewGuid(), email, name);
                user.PreferredCulture  = string.IsNullOrWhiteSpace(preferredCulture) ? StrixPlatform.CurrentCultureCode : preferredCulture;
                user.DateAcceptedTerms = acceptedTerms ? (DateTime?)DateTime.Now : null;

                var security = new UserSecurity(user.Id);
                security.Password            = encodedPassword;
                security.Approved            = isApproved || StrixMembership.Configuration.Registration.AutoApproveUsers;
                security.RegistrationComment = registrationComment;

                var session = new UserSessionStorage(user.Id);

                user     = this._dataSource.Save(user);
                security = this._dataSource.Save(security);
                session  = this._dataSource.Save(session);

                if (security == null || session == null)
                {
                    user = null;
                }
            }

            if (user != null)
            {
                var args = new Dictionary <string, object>();
                args.Add("Id", user.Id);
                args.Add("UserName", user.Name);
                args.Add("UserEmail", user.Email);
                StrixPlatform.RaiseEvent <GeneralEvent>(new GeneralEvent("UserCreateEvent", args));
            }

            return(user);
        }
コード例 #3
0
        public void SaveSession(Guid userId, IDictionary <string, object> sessionValues)
        {
            if (userId == Guid.Empty)
            {
                throw new ArgumentException("Parameter cannot be empty", "userId");
            }

            var session = this._dataSource.Query <UserSessionStorage>().FirstOrDefault(u => u.Id == userId);

            if (session == null)
            {
                session = new UserSessionStorage(userId);
            }

            var serializableValues = JsonConvert.SerializeObject(sessionValues);

            session.Session = serializableValues;
            this._dataSource.Save(session);
        }
コード例 #4
0
        public void SaveSession(Guid userId, IDictionary<string, object> sessionValues)
        {
            if (userId == Guid.Empty)
            {
                throw new ArgumentException("Parameter cannot be empty", "userId");
            }

            var session = this._dataSource.Query<UserSessionStorage>().FirstOrDefault(u => u.Id == userId);

            if (session == null)
            {
                session = new UserSessionStorage(userId);
            }

            var serializableValues = JsonConvert.SerializeObject(sessionValues);
            session.Session = serializableValues;
            this._dataSource.Save(session);
        }
コード例 #5
0
        public User Create(string name, string email, string preferredCulture, string password, bool isApproved, bool acceptedTerms, string registrationComment)
        {
            if (string.IsNullOrWhiteSpace(email))
            {
                throw new ArgumentNullException("email");
            }

            this.CheckEmailAvailable(email);
            User user = this._dataSource.Query<User>().FirstOrDefault(u => u.Email.ToLower() == email.ToLower());

            if (user == null)
            {
                CheckPassword(password);
                var encodedPassword = this._securityManager.EncodePassword(password);

                user = new User(Guid.NewGuid(), email, name);
                user.PreferredCulture = string.IsNullOrWhiteSpace(preferredCulture) ? StrixPlatform.CurrentCultureCode : preferredCulture;
                user.DateAcceptedTerms = acceptedTerms ? (DateTime?)DateTime.Now : null;

                var security = new UserSecurity(user.Id);
                security.Password = encodedPassword;
                security.Approved = isApproved || StrixMembership.Configuration.Registration.AutoApproveUsers;
                security.RegistrationComment = registrationComment;

                var session = new UserSessionStorage(user.Id);

                user = this._dataSource.Save(user);
                security = this._dataSource.Save(security);
                session = this._dataSource.Save(session);

                if (security == null || session == null)
                {
                    user = null;
                }
            }

            if (user != null)
            {
                var args = new Dictionary<string, object>();
                args.Add("Id", user.Id);
                args.Add("UserName", user.Name);
                args.Add("UserEmail", user.Email);
                StrixPlatform.RaiseEvent<GeneralEvent>(new GeneralEvent("UserCreateEvent", args));
            }

            return user;
        }
コード例 #6
0
        private void CreateAdminUser()
        {
            var adminId = Guid.NewGuid();
            string password = this._securityManager.EncodePassword(Resources.DefaultValues.AdministratorPassword);
            var admin = new User(adminId, Resources.DefaultValues.AdministratorEmail, Resources.DefaultValues.AdministratorName);
            admin.PreferredCulture = StrixPlatform.DefaultCultureCode;
            this._dataSource.Save(admin);

            var security = new UserSecurity(admin.Id);
            security.Password = password;
            security.Approved = true;
            this._dataSource.Save(security);

            var session = new UserSessionStorage(admin.Id);
            this._dataSource.Save(session);

            var userRole = new UserInRole(this._adminRole, admin.Id, DateTime.Now, null);
            admin.Roles = new List<UserInRole>() { userRole };
        }