def post(): 
        content = request.form
        
        user = User()
        user.role = content.get('role', None)
        user.username = content.get('username', '')
        user.password = content.get('password', '')
        user.email = content.get('email', '')
        user.first_name = " ".join(word.capitalize() for word in content.get('firstName', '').split())
        user.middle_name = " ".join(word.capitalize() for word in content.get('middleName', '').split())
        user.last_name = " ".join(word.capitalize() for word in content.get('lastName', '').split())
        user.phone_number = content.get('phoneNumber', '')
        user.unit_number = content.get('unitNumber', '')
        user.street_address = content.get('streetAddress', '')
        user.suburb = content.get('suburb', '')
        user.postcode = content.get('postcode', '')
        user.state = content.get('state', '')
        user.country = content.get('country', '')

        try: 
            user.save()
        except:
            return render_json(500, {'message': "An error occurred."})
        
        return render_json(200, {'user': user.to_json()})
Пример #2
0
 def post(self):
     args = self.reqparse.parse_args()
     user = User(username=args['username'], password=args['password'])
     try:
         user.save()
     except IntegrityError as err:
         return {'error_message': err.message}, 409
     return {'user': user.serialize()}, 201
Пример #3
0
def signup():
    form = SignupForm()

    if form.validate_on_submit():
        u = User()

        form.populate_obj(u)
        u.password = User.encrypt_password(request.form.get('password'))
        u.save()

        if login_user(u):
            flash('Awesome, thanks for signing up!', 'success')
            return redirect(url_for('user.welcome'))

    return render_template('user/signup.html', form=form)