Example #1
0
    def get(self, request):
        if not config.debug:
            return error_forbidden('can only be accessed in debug mode')
        
        log.debug('{0}: {1}'.format(request, request.match_info))
        email = request.match_info['email']
        
        try:
            user = User.select().where(User.email == email).get()
        except User.DoesNotExist as exc:
            return self.error_unauthorized('Invalid email validation URL')

        reply = dict(
            success=True,
            user=dict(
                join_date=str(user.join_date),
                name=user.name,
                email=user.email,
                password=user.password,
                email_validated=user.email_validated,
                email_validation_secret=user.email_validation_secret,
                recovery_requested=user.recovery_requested,
                recovery_date=str(user.recovery_date),
                recovery_secret=user.recovery_secret,
            ),
        )
        return web.Response(body=json.dumps(reply).encode('utf-8'))
Example #2
0
def add_sample_user():
    try:
        user = User.create_from_registration('Nicolas Bourbaki', '*****@*****.**', '57')
    except EmailExistsException:
        return
    user.email_validated = True
    user.save()
Example #3
0
    def post(self, request):
        data = yield from request.read()
        log.debug('{0}: {1}'.format(request, data))
        if not data:
            return self.error_bad_request('Empty request')
        data = yield from request.json()
        email = data['email']
        password = data['password']

        try:
            user = User.login(email, password)
        except (EmailNotVerifiedException, InvalidPasswordException) as exc:
            return self.error_forbidden(exc)

        reply = dict(
            success=True,
            jwt=jwt_encode(email)
        )
        return web.Response(body=json.dumps(reply).encode('utf-8'))
Example #4
0
    def post(self, request):
        data = yield from request.read()
        log.debug('{0}: {1}'.format(request, data))
        data = yield from request.json()
        secret = data['secret']

        try:
            user = User.select().where(User.email_validation_secret == secret).get()
        except User.DoesNotExist as exc:
            return self.error_unauthorized('Invalid email validation URL')
        else:
            user.email_validated = True
            user.save()
        
        reply = dict(
            success=True,
            name=user.name,
            email=user.email,
        )
        return web.Response(body=json.dumps(reply).encode('utf-8'))
Example #5
0
def register() -> None:
    if request.method == 'GET':
        return render_template("auth/register.html")
    else:
        try:
            user = User(
                request.form['email'],
                generate_password_hash(request.form['password']),
                request.form['firstName'],
                request.form['lastName'],
            )

            # check if the post request has the file part
            # uploaded_file = None
            # filename = None
            # if 'file' not in request.files:
            #     print('fileinrequest')
            #     file = request.files['image']
            #     if file:
            #         print(file.filename)
            #         file_ext = FileManager.get_file_extension(
            #             file.filename)
            #         print(file_ext)
            #         filename = FileManager.get_profile_filename(
            #             request.form['email'], file_ext)
            #         print(filename)
            #         FileManager.save_file(file, filename)
            #         print('filesaved')
            #         # file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            #           user.picture = filename

            db.session.add(user)
            db.session.commit()

            return redirect(url_for('auth.signin'))
        except Exception as e:
            return render_template("auth/register.html", error=e.args[0])
Example #6
0
    def post(self, request):
        data = yield from request.read()
        log.debug('{0}: {1}'.format(request, data))
        data = yield from request.json()
        name = data['name']
        email = data['email']
        password = data['password']

        if not KnownEmail.select().where(KnownEmail.email == email).exists():
            return self.error_forbidden('Email address must appear in the git commit log')
        
        try:
            user = User.create_from_registration(name, email, password)
        except EmailExistsException as exc:
            return self.error_forbidden(exc);

        asyncio.get_event_loop().create_task(self.send_validation_link(user))

        reply = dict(
            success=True,
            name=name,
            email=email,
        )
        return web.Response(body=json.dumps(reply).encode('utf-8'))