Beispiel #1
0
        public async Task <CreateReturnType> CreateAsync(UserCreateDTO user)
        {
            if (user.Username == "" || user.Username is null)
            {
                return(MISSING_USERNAME);
            }

            if (user.Password1 == "" || user.Password1 is null)
            {
                return(MISSING_PASSWORD);
            }

            if (!user.Email.Contains("@"))
            {
                return(INVALID_EMAIL);
            }

            if (user.Password1 != user.Password2)
            {
                return(PASSWORD_MISMATCH);
            }

            var usernamecheck = from u in context.users where u.username == user.Username select u;

            if (await usernamecheck.AnyAsync())
            {
                return(USERNAME_TAKEN);
            }

            var emailcheck = from u in context.users where u.email == user.Email select u;

            if (await emailcheck.AnyAsync())
            {
                return(EMAIL_TAKEN);
            }

            var newUser = new User
            {
                username = user.Username,
                email    = user.Email,
                pw_hash  = HashPassword(user.Password1)
            };

            await context.users.AddAsync(newUser);

            await context.SaveChangesAsync();

            return(CreateReturnType.SUCCESS);
        }
Beispiel #2
0
        public async Task <int> CreateAsync(string message, string username)
        {
            var userQuery = from u in context.users where u.username == username select u;

            if (!await userQuery.AnyAsync())
            {
                return(-1);
            }

            var user = await userQuery.FirstAsync();

            var newMessage = new Message
            {
                User     = user,
                text     = message,
                pub_date = DateTime.Now,
                flagged  = 0
            };
            await context.messages.AddAsync(newMessage);

            await context.SaveChangesAsync();

            return(newMessage.message_id);
        }
Beispiel #3
0
        public async Task <int> CreateAsync(UserCreateDTO user)
        {
            if (!user.Password1.Equals(user.Password2))
            {
                return(-1);
            }
            var usernamecheck = from u in context.users where u.username == user.Username select u;

            if (await usernamecheck.AnyAsync())
            {
                return(-2);
            }
            var emailcheck = from u in context.users where u.email == user.Email select u;

            if (await emailcheck.AnyAsync())
            {
                return(-3);
            }
            if (!user.Email.Contains("@"))
            {
                return(-4);
            }

            var newUser = new User
            {
                username = user.Username,
                email    = user.Email,
                pw_hash  = HashPassword(user.Password1)
            };

            await context.users.AddAsync(newUser);

            await context.SaveChangesAsync();

            return(newUser.user_id);
        }