Ejemplo n.º 1
0
def register():
    if request.method == 'POST':
        e_mail = request.form['email']
        name = request.form['username']
        passwrd = generate_password_hash(request.form['password'])
        if bool(re.search(r'@', e_mail)) is False:
            flash("Email must have an @ symbol")
            return render_template('register.html')
        if len(request.form['password']) > 12 or len(
                request.form['password']) < 6:
            flash("Password length must be between 12 and 6 chars")
            return render_template('register.html')
        User.create(username=name, password=passwrd, email=e_mail)
        flash("New User added successfully!")
    return render_template('register.html')
Ejemplo n.º 2
0
 def post(self):
     args = parser.parse(UserAPI.WEBARGS, request)
     try:
         user = User.create(args["username"], args["email"])
         return make_response(jsonify(user.to_dict()), 200)
     except exc.IntegrityError as e:
         errorInfo = e.orig.args
         error_message = errorInfo[0]
         raise exceptions.APIException(
             message='Unable to create user, duplicates found: {}'.format(
                 error_message))