private User CreateRegularUser(string username, string email, string password)
        {
            var sameUser = this.Forum.Users.FirstOrDefault(u => u.Username == username || u.Email == email);

            if (sameUser == null)
            {
                User user = new User(this.Forum.Users.Count + 1, username, password, email);
                return user;
            }
            else
            {
                return null;
            }
        }
Example #2
0
        public override void Execute()
        {
            var users = this.Forum.Users;
            string username = this.Data[1];
            string password = PasswordUtility.Hash(this.Data[2]);
            string email = this.Data[3];

            if (users.Any(u => u.Username == username || u.Email == email))
            {
                throw new CommandException(Messages.UserAlreadyRegistered);
            }

            User user;

            if (this.Data.Count > 4)
            {
                var role = this.Data[4];

                switch (role.ToLower())
                {
                    case "administrator":
                        if (users.Any())
                        {
                            throw new CommandException(Messages.RegAdminNotAllowed);
                        }

                        user = new Admin(username, password, email);

                        break;

                    default:
                        user = new User(users.Count + 1, username, password, email);
                        break;
                }
            }
            else
            {
                user = new User(users.Count + 1, username, password, email);
            }

            users.Add(user);

            this.Forum.Output.AppendLine(
                string.Format(Messages.RegisterSuccess, username, users.Last().Id)
            );
        }