Inheritance: IEntity
示例#1
0
        public static void Update(User user)
        {
            user.Name = user.Email;

            User user2 = GetUser(user.Email);
            if (user2 != null && user2.ID != user.ID)
                throw new Exception("There is another user has the same e-mail, please choose another e-mail");

            UserDataMapper.Update(user);
        }
示例#2
0
        public static int Add(User user)
        {
            user.Name = user.Email;

            User user2 = GetUser(user.Email);
            if (user2 != null)
                throw new Exception("There is another user has the same e-mail, please choose another e-mail");

            return UserDataMapper.Add(user);
        }
示例#3
0
        public static void LoginIn(User user, bool WithRoles)
        {
            if (user != null)
            {
                HttpContext.Current.Session[CoreConfigurationManager._CoreConfigSectionHandler.SecurityElement.SessionCurrentUserKey] = user;

                if (WithRoles)
                {
                    List<FormUser> formsUser = FormUserManager.GetFormsUsers(-1, user.ID);
                    Dictionary<string, CMSEnums.AccessType> formsUserAccess = new Dictionary<string, CMSEnums.AccessType>();
                    for (int i = 0; i < formsUser.Count; i++)
                    {
                        formsUserAccess.Add(formsUser[i].FormCode, formsUser[i].AccessType);
                    }
                    HttpContext.Current.Session[CoreConfigurationManager._CoreConfigSectionHandler.SecurityElement.SessionCurrentFormKey] = formsUserAccess;

                    List<FormRole> formsRoles = FormRoleManager.GetFormsRolesByUserID(user.ID);
                    HttpContext.Current.Session[CoreConfigurationManager._CoreConfigSectionHandler.SecurityElement.SessionCurrentRoleKey] = formsRoles;
                }
            }
        }
示例#4
0
        internal static void FillFromReader(User user, SqlDataReader reader)
        {
            int colIndex = 0;

            int days = 0, seconds = 0;
            colIndex = reader.GetOrdinal(CN_USER_CREATION_DAY);
            if (!reader.IsDBNull(colIndex))
                days = reader.GetInt32(colIndex);

            colIndex = reader.GetOrdinal(CN_USER_CREATION_SEC);
            if (!reader.IsDBNull(colIndex))
                seconds = reader.GetInt32(colIndex);

            user.CreationDate = CMSCoreHelper.GetDateTime(days, seconds);

            colIndex = reader.GetOrdinal(CN_USER_EMAIL);
            if (!reader.IsDBNull(colIndex))
                user.Email = reader.GetString(colIndex);

            colIndex = reader.GetOrdinal(CN_USER_ID);
            if (!reader.IsDBNull(colIndex))
                user.ID = reader.GetInt32(colIndex);

            colIndex = reader.GetOrdinal(CN_USER_IS_ACTIVE);
            if (!reader.IsDBNull(colIndex))
                user.IsActive = reader.GetBoolean(colIndex);

            colIndex = reader.GetOrdinal(CN_USER_IS_DELETED);
            if (!reader.IsDBNull(colIndex))
                user.IsDeleted = reader.GetBoolean(colIndex);

            colIndex = reader.GetOrdinal(CN_USER_NAME);
            if (!reader.IsDBNull(colIndex))
                user.Name = reader.GetString(colIndex);

            colIndex = reader.GetOrdinal(CN_USER_PASSWORD);
            if (!reader.IsDBNull(colIndex))
                user.Password = EncryptAndDecrypt.Decrypt(reader.GetString(colIndex), true);
        }
示例#5
0
        internal static User GetUser(List<User> users, SqlDataReader reader)
        {
            int colIndex = 0;
            colIndex = reader.GetOrdinal(CN_USER_ID);
            int value = reader.GetInt32(colIndex);

            User user = users.Where(c => c.ID == value).FirstOrDefault();
            if (user == null)
            {
                user = new User();
                users.Add(user);
            }
            return user;
        }
示例#6
0
        internal static User GetUserByUserName(string UserName)
        {
            User user = null;

            using (SqlConnection sqlConnection = new SqlConnection(CMSCoreBase.CMSCoreConnectionString))
            {
                SqlCommand sqlCommand = new SqlCommand(SN_USER_GET_BY_NAME, sqlConnection);
                sqlCommand.CommandType = System.Data.CommandType.StoredProcedure;

                SqlParameter parameter = new SqlParameter(PN_USER_NAME, System.Data.SqlDbType.NVarChar);
                parameter.Direction = System.Data.ParameterDirection.Input;
                parameter.Value = UserName;
                sqlCommand.Parameters.Add(parameter);

                sqlCommand.Connection.Open();
                using (SqlDataReader reader = sqlCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection))
                {
                    while (reader.Read())
                    {
                        if (user == null)
                            user = new User();
                        FillFromReader(user, reader);
                    }
                    reader.Close();
                    sqlCommand.Connection.Close();
                }
            }
            return user;
        }