Exemple #1
0
        public async Task <IActionResult> ResendEmail([FromBody] Login body)
        {
            await Db.Connection.OpenAsync();

            body.Email = body.Email.ToLower();

            //create user object and fill it with user
            UserQuerry resend     = new UserQuerry(Db);
            User       resendUser = await resend.GetUserByEmail(body.Email);

            // check if user is verified
            if (resendUser.Verified != "true")
            {
                // if not resend email
                MailHandler mailHandler = new MailHandler();
                mailHandler.Execute(body.Email, resendUser.FirstName, resendUser.Verified);
                Db.Dispose();
                return(new OkObjectResult("email resend"));
            }
            else
            {
                // if is then give error
                Db.Dispose();
                return(new ConflictObjectResult("User Already verified"));
            }
        }
Exemple #2
0
        public async Task <IActionResult> RegisterUser([FromBody] User body)
        {
            // Email should always be lowercase
            body.EmailToLowerCase();

            // Open database connection
            await Db.Connection.OpenAsync();

            UserQuerry loginUser = new UserQuerry(Db);

            // Check if there is already an user with this email or username
            User user = await loginUser.GetUserByEmail(body.Email);

            User user2 = await loginUser.GetUserByUsername(body.Username);

            UserQuerry registerUser = new UserQuerry(Db);

            if (await registerUser.GetUserByEmail(body.Email) == null &&
                await registerUser.GetUserByUsername(body.Username) == null)
            {
                body.Db       = Db;
                body.Verified = Helpers.SecureRandomNumber(42);
                body.HashPass();
                await body.InsertAsync();

                MailHandler mailHandler = new MailHandler();

                mailHandler.Execute(body.Email, body.FirstName, body.Verified);

                Db.Dispose();
                return(new OkObjectResult("Account succesfully made"));
            }

            Db.Dispose();
            return(new BadRequestObjectResult("Account already exists"));
        }