Ejemplo n.º 1
0
        /// <summary>
        /// Adds a new user
        /// </summary>
        /// <param name="form">User data</param>
        /// <returns>success</returns>
        public bool add(Form_User_Add form)
        {
            user newUser = new user();
            newUser.username = form["username"].getValue();
            newUser.rolesid = long.Parse(form["role"].getValue());
            newUser.email = form["email"].getValue();

            SHA1Managed sha = new SHA1Managed();
            string hash = BitConverter.ToString(sha.ComputeHash(Encoding.Default.GetBytes(form["password"].getValue()))).Replace("-", String.Empty).ToLower();

            newUser.password = hash;
            newUser.date = DateTime.Now;

            using (UserDataContext u = new UserDataContext())
            {
                try
                {
                    u.users.InsertOnSubmit(newUser);
                    u.SubmitChanges();
                }
                catch (Exception e)
                {
                    CMS.Services.CMS_Services_Message.getInstance().addError(e.Message);
                    return false;
                }
            }

            return true;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets edit data for edit mode
        /// </summary>
        /// <param name="u">user</param>
        public void setEditData(user u)
        {
            this._action = new CMS_Action("/backend/EditUser?id=" + u.id.ToString());

            this._elements["username"].setValue(u.username);
            this._elements["role"].setValue(u.rolesid.ToString());
            this._elements["email"].setValue(u.email);

            this._elements["password"].setRequired(false);

            this._elements["ok"].setLabel("Save changes");
        }
Ejemplo n.º 3
0
 partial void Deleteuser(user instance);
Ejemplo n.º 4
0
 partial void Updateuser(user instance);
Ejemplo n.º 5
0
 partial void Insertuser(user instance);
Ejemplo n.º 6
0
        /// <summary>
        /// Save changes to the given user
        /// </summary>
        /// <param name="form">User data</param>
        /// <param name="edited">Edited user</param>
        /// <returns>success</returns>
        public bool save(Form_User_Add form, user edited)
        {
            user toSave = new user();
            toSave.id = edited.id;
            toSave.password = edited.password;
            if (form["password"].getValue() != String.Empty)
            {
                SHA1Managed sha = new SHA1Managed();
                string hash = BitConverter.ToString(sha.ComputeHash(Encoding.Default.GetBytes(form["password"].getValue()))).Replace("-", String.Empty).ToLower();
                toSave.password = hash;
            }
            toSave.rolesid = long.Parse(form["role"].getValue());
            toSave.email = form["email"].getValue();
            toSave.username = form["username"].getValue();
            toSave.date = edited.date;

            using (UserDataContext u = new UserDataContext())
            {
                u.users.Attach(toSave, edited);
                try
                {
                    u.SubmitChanges();
                }
                catch (Exception e)
                {
                    return false;
                }
            }

            return true;
        }