Ejemplo n.º 1
0
def send_activation_email(user: User) -> None:
    email_content = get_template(
        "authorization/templates/activation.html",
        activation_link=get_activation_link(user),
    )
    send_email(user.email, "Activate your Gamers' Plane account!",
               email_content)
Ejemplo n.º 2
0
 def is_valid(self):
     insert_into_spreadsheet(self.data['email_signup'])
     send_email(from_email=os.environ.get('EMAIL'),
                body='Thank you for signing up for our newsletter.',
                to=[self.data['email_signup']],
                reply_to=[None],
                subject='Thank you!')
     return super(EmailForm, self).is_valid()
Ejemplo n.º 3
0
 def send_email(self):
     email = self.cleaned_data['email']
     name = self.cleaned_data['name']
     message = self.cleaned_data['message'] + f"\nFrom: {name}"
     send_email(body=message,
                from_email=email,
                to=[os.environ.get("EMAIL")],
                reply_to=[email],
                subject=f'Message from {name}')
Ejemplo n.º 4
0
    def confirmed_acceptance_email(student, listing):
        message = ConfirmAcceptance.confirmed_message(
            f'{student.first_name} {student.last_name}', listing.title)

        send_email(body=message,
                   from_email=os.environ.get("EMAIL"),
                   to=[listing.company.email],
                   subject=f"Student Confirmed!",
                   reply_to=[student.email])
Ejemplo n.º 5
0
    def accept_student_email(student, listing):
        message = AcceptStudent.accept_student_msg(listing.company,
                                                   listing.title)

        send_email(body=message,
                   from_email=os.environ.get("EMAIL"),
                   to=[student.email],
                   subject=f"Congratulations! ({listing.title})",
                   reply_to=[listing.company.email])
Ejemplo n.º 6
0
    def request_interview_email(student, listing) -> None:
        email = student.email
        message = RequestInterview.request_interview_msg(
            listing.company, listing.title)

        send_email(body=message,
                   from_email=os.environ.get("EMAIL"),
                   to=[email],
                   subject=f"Next steps for {listing.title}",
                   reply_to=[listing.company.email])
Ejemplo n.º 7
0
    def reject_student_email(student, listing):
        email = student.email

        message = RejectStudent.reject_student_msg(listing.company,
                                                   listing.title)

        send_email(body=message,
                   from_email=os.environ.get("EMAIL"),
                   to=[email],
                   subject=f"Response for {listing.title}",
                   reply_to=[listing.company.email])
Ejemplo n.º 8
0
    def post(self):
        email_input = request.form.get('email').lstrip()
        email = email_input.lower()

        is_valid_email = validate_email(email)

        if email == '':
            response = jsonify({
                'message': 'This field is required'
            })
            response.status_code = 400
            return response
        if is_valid_email == False:
            response = jsonify({
                'message': 'Oops! You have inputed an invalid email.'
            })
            response.status_code = 400
            return response

        user = User.query.filter_by(email=email).first()

        if user == None:
            response = jsonify({
                'message': 'The email entered is not registered.'
            })
            response.status_code = 404
            return response
        elif user.confirmed == True:
            response = jsonify({
                'message': 'This email has already been verified.'
            })
            response.status_code = 409
            return response
        else:
            email_token = user.generate_email_token(user.email)

            confirm_url = 'http://%s/api/auth/email-confirmation/?emailtoken=%s' % (os.getenv(
                'HOST_URL'), email_token.decode())

            html = email_template(confirm_url)

            subject = "Please confirm your mail"

            send_email(user.email, subject, html)

            response = jsonify({
                'message': 'An email confirmation link has been sent to this email: %s' % (user.email)
            })
            response.status_code = 200
            return response
    def post(self):
        # .lstrip() Removes all whitespaes
        email_input = request.form.get('email').lstrip()
        email = email_input.lower()

        is_valid_email = validate_email(email)

        # User input validations
        if email == '':
            response = jsonify({
                'message': 'This field is required'
            })
            response.status_code = 400
            return response
        if is_valid_email == False:
            response = jsonify({
                'message': 'Oops! You have inputed an invalid email.'
            })
            response.status_code = 400
            return response

        user = User.query.filter_by(email=email).first()
        if user == None:
            response = jsonify({
                'message': 'This email is not registered.'
            })
            response.status_code = 404
            return response
        else:
            # Generate password token
            password_reset_token = user.generate_email_token(user.email)
            # Password Reset Link
            password_confirm_url = 'http://%s/api/auth/reset-password/?resettoken=%s' % (os.getenv(
                'HOST_URL'), password_reset_token.decode())
            # Password reset template
            password_template = forget_password_template(password_confirm_url)

            subject = "Password Reset Link"
            # Call the method that sends the mail inserting all arguments
            send_email(user.email, subject, password_template)

            response = jsonify({
                'message': 'A password reset link has been sent to this email: %s' % (user.email)
            })
            response.status_code = 200
            return response
def donate(img_id):
    result = transact({
        'amount': request.form['amount'],
        'payment_method_nonce': request.form['payment_method_nonce'],
        'options': {
            "submit_for_settlement": True
        }
    })
    if result.is_success or result.transaction:
        flash('Donate successfully', 'success')
        image = Image.get_by_id(img_id)
        send_email(recipient=image.user.email, donor=current_user.email, amount=result.transaction.amount)
        Transaction(image_id=img_id, user_id=current_user.id, transaction_history=result.transaction.id, amount=result.transaction.amount).save()
        return redirect(url_for('users.show_donate',transaction_id=result.transaction.id))
    else:
        flash('Donate failed', 'error')
        for x in result.errors.deep_errors: flash('Error: %s: %s' % (x.code, x.message),'error')
        return redirect(url_for('users.donate_form',img_id=img_id))
Ejemplo n.º 11
0
def generate_password_reset():
    fields_missing = require_values(request.json, ["email"])
    if len(fields_missing):
        return response.errors({"fields_missing": fields_missing})

    email = request.json["email"]
    try:
        user = User.objects.get(email=email)
    except User.DoesNotExist:
        return response.errors({"no_account": True})

    try:
        password_reset = PasswordResetToken.objects.get(user=user)
    except PasswordResetToken.DoesNotExist:
        password_reset = PasswordResetToken(user=user)
        password_reset.save()
    email_content = get_template(
        "authorization/templates/reset_password.html",
        reset_link="http://gamersplane.com/auth/resetPass/" +
        password_reset.token,
    )
    send_email(email, "Password reset for Gamers' Plane", email_content)

    return response.success()
Ejemplo n.º 12
0
    def post(self):
        email_input = request.form.get('email').lstrip()
        email = email_input.lower()

        # Remove whitespaces from left and right
        username_input = request.form.get('username').lstrip()
        username = username_input.lower()

        password = request.form.get('password')
        confirm_password = request.form.get('confirm_password')

        phone_number = request.form.get('phone_number').lstrip()
        firstname = request.form.get('firstname')
        lastname = request.form.get('lastname')
        confirmed = False

        # validate email as a valid email address without using regex
        is_valid = validate_email(email)

        # validate user inputs
        if email == '' or password == '' or phone_number == '' or username == '':
            response = jsonify({'message': 'This field is required.'})
            response.status_code = 400
            return response
        if len(password) < 6:
            response = jsonify(
                {'message': 'Password should be greater than 6 characters'})
            response.status_code = 400
            return response
        if password != confirm_password:
            response = jsonify({
                'message':
                'Oops! Sorry. The passwords you inputted are not the same.'
            })
            response.status_code = 400
            return response

        # This validate if what is inputed are all numbers
        if phone_number.isnumeric() == False:
            response = jsonify(
                {'message': 'Phone numbers must all contain numbers'})
            response.status_code = 400
            return response
        if len(phone_number) < 8:
            response = jsonify({
                'message':
                'Phone number should be greater than 8 characters'
            })
            response.status_code = 400
            return response
        if len(username) < 2:
            response = jsonify(
                {'message': 'Username should be greater than 2 characters'})
            response.status_code = 400
            return response
        if is_valid == False:
            response = jsonify({'message': 'Invalid Email Inputed'})
            response.status_code = 400
            return response
        else:

            password_hash = User.generate_password_hash(self, password)

            # Find user email in the database
            user = User.query.filter_by(email=email,
                                        phone_number=phone_number).first()

            # If User is not found do this
            if user == None:
                try:
                    # Register the user
                    email = email
                    password = password_hash
                    phone_number = phone_number
                    firstname = firstname
                    lastname = lastname
                    confirmed = confirmed
                    user = User(email=email,
                                password=password,
                                phone_number=phone_number,
                                firstname=firstname,
                                lastname=lastname,
                                username=username,
                                confirmed=confirmed)
                    user.save()

                    # Generate Authentication token for the user using the user_id
                    access_token = user.generate_token(user.id)

                    auth_user_email = user.generate_email_token(user.email)

                    confirm_url = 'http://%s/api/auth/email-confirmation/?emailtoken=%s' % (
                        os.getenv('HOST_URL'), auth_user_email.decode())

                    html = email_template(confirm_url)

                    subject = "Please confirm your mail"

                    send_email(user.email, subject, html)

                    response = jsonify({
                        'email':
                        user.email,
                        'password':
                        user.password,
                        'username':
                        user.username,
                        'access_token':
                        access_token.decode(),
                        'email_validation':
                        user.confirmed,
                        'message':
                        'Registration Successful. An email has been sent to this email: '
                        + user.email +
                        '. Please confirm your email to proceed.'
                    })

                    # return a response notifying the user that they registered
                    response.status_code = 201
                    return response

                except Exception as e:
                    # An error occured, therefore return a string message containing the error
                    response = jsonify({
                        'message': str(e),
                    })
                    response.status_code = 409
                    return response
            else:
                # There is an existing user. We don't want to register users twice
                # Return a message to the user telling them that the email, username or phone number is been used by another user
                response = jsonify({
                    'message':
                    'Email or phone number is already been used by an existing user. Please try again.'
                })

                response.status_code = 409
                return response
Ejemplo n.º 13
0
def finish_file_upload(*, bucket_and_key, upload_id, file_chunks, video_name, user_email, already_uploaded=0, upload_results=[]):
    if len(upload_results) != already_uploaded:
        raise ValueError("Invalid length of upload_results: {}. Must be {}".format(len(upload_results), already_uploaded))

    results = list(upload_results)

    s3 = boto3.client(
        "s3",
        "us-east-2",
        aws_access_key_id=settings.AWS_ACCESS_KEY_ID,
        aws_secret_access_key=settings.AWS_SECRET_ACCESS_KEY
    )

    try:
        count = already_uploaded + 1
        chunk = file_chunks[already_uploaded]
        ln = len(file_chunks)

        while count <= ln:
            bts = bytearray.fromhex(chunk)

            response = s3.upload_part(
                **bucket_and_key,
                PartNumber=count,
                UploadId=upload_id,
                Body=bts
            )

            results.append({
                "ETag": response["ETag"][1:-1],
                "PartNumber": count
            })

            if ln == count:
                break

            chunk = file_chunks[count]
            count += 1
        
        s3.complete_multipart_upload(
            **bucket_and_key,
            UploadId=upload_id,
            MultipartUpload={
                "Parts": results
            }
        )

        send_email(
            [user_email],
            "Video upload finished!",
            "<h3>Your upload job of video '{}' was successfully finished!</h3>".format(video_name)
        )
    except Exception as exc:
        print(exc)
        s3.abort_multipart_upload(**bucket_and_key, UploadId=upload_id)

        send_email(
            [user_email],
            "Video upload failed.",
            "<h3>Your upload job of video '{}' failed. Check the video file and try again.</h3>".format(video_name)
        )