Пример #1
0
    def post(self):
        # register user
        args = user_reqparse.parse_args()
        try:
            role = Role.query.filter_by(permissions=2).first()
            user = User.create(email=args['email'],
                               username=args['username'],
                               password=args['password'],
                               location=args.get('location'),
                               about_me=args.get('about'),
                               role=role)
        except (IntegrityError, InvalidRequestError, DataError):
            raise UserAlreadyExistsError()

        token = user.generate_confirm_token(expiration=86400)
        email_token = user.generate_email_token()
        send_email.delay(to=user.email,
                         subject='Confirm Your Account',
                         template='mail/confirm',
                         user=user.username,
                         url=url_for('auth.email_auth',
                                     token=email_token,
                                     _external=True))
        current_app.logger.info('New User Exist: {}, {}'.format(
            user.id, user.email))
        return {'token': token, 'permission': user.role.permissions},
Пример #2
0
 def register_user(self):
     role = Role.query.filter_by(name='Administrator').first()
     user = User.create(username='******',
                        email='*****@*****.**',
                        password='******',
                        role=role,
                        confirmed=True,
                        about_me='Python爱好者'
                        )
     return user
Пример #3
0
 def test_add_user(self):
     role = Role.query.filter_by(name='Administrator').first()
     user = User.create(username='******',
                        email='*****@*****.**',
                        password='******',
                        role=role,
                        confirmed=True,
                        about_me='Python')
     db.session.add(user)
     db.session.commit()
     user.json()
Пример #4
0
    def test_user_register(self):
        role = Role.query.filter_by(name='Administrator').first()
        user = User.create(username='******',
                           email='*****@*****.**',
                           password='******',
                           role=role,
                           confirmed=True,
                           about_me='Python爱好者'
                           )
        user.to_json()
        token = user.generate_confirm_token(expiration=86400)
        email_token = user.generate_email_token()
        user.is_administrator()
        user.verify_auth_token(token)
        user.verify_email_token(email_token)

        password_token = user.generate_reset_token()
        user.verify_reset_token(password_token, 'password')

        change_email_token = user.generate_change_mail_token(
            new_email='*****@*****.**')
        user.verify_change_mail(change_email_token)