コード例 #1
0
        /// <summary>
        /// Adds the given user to the database
        /// </summary>
        /// <param name="user">ASC user</param>
        public DBUserAuthentification AddUser(ref DBUser user)
        {
            if (!CanChangeName(user?.Name) || user is null)
            {
                return(null);
            }

            user.ID = NextID(USERS);

            while (HasUser(user.ID))
            {
                ++user.ID;
            }

            DBUserAuthentification auth = new DBUserAuthentification
            {
                ID   = user.ID,
                Salt = Authentification.GenerateSaltString(),
            };

            if (!ValidateUser(user))
            {
                return(null);
            }

            var sql = GetScript(nameof(AddUser), user.ID, auth.Salt, user.Name, user.Status, user.IsAdmin ? 1 : 0, user.IsBlocked ? 1 : 0);

            ExecuteVoid(sql);

            user = GetUser(user.ID); // update user

            $"Added user {{{user.UUID}}}".Ok();

            return(DecodeUAuth(auth));
        }