Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. #I don't know if it is for the desabled attribute, if the user
  2. #is not logged so he cannot create a admin account only a normal account.
  3. {% if g.user['type'] == 0 %}
  4. <div class="form-group">
  5. <label for="type_user">Type of User <span style="color: red">*</span></label>
  6. <select class="form-control" id="type_user" name="type_user" required>
  7. <option value="0">Admin</option>
  8. <option value="1">User</option>
  9. </select>
  10. </div>
  11. {% else %}
  12. <div class="form-group">
  13. <label for="type_user">Type of User <span style="color: red">*</span></label>
  14. <select class="form-control" id="type_user" name="type_user" required disabled>
  15. <option value="1">User</option>
  16. </select>
  17. </div>
  18. {% endif %}
  19.  
  20. @bp.route('/register', methods=('GET', 'POST'))
  21. def register():
  22. if request.method == 'POST':
  23. first_name = request.form['first_name']
  24. last_name = request.form['last_name']
  25. type_user = int(request.form.get('type_user'))
  26. username = request.form['username']
  27. password = request.form['password']
  28. db = get_db()
  29. error = None
  30. print(type_user)
  31. print(first_name)
  32. if not (first_name and last_name and type_user and username and password):
  33. error = "Please fill all requiered fields"
  34.  
  35. elif db.execute(
  36. 'SELECT id FROM user WHERE username = ?', (username,)
  37. ).fetchone() is not None:
  38. error = 'User {} is already registered.'.format(username)
  39.  
  40. if error is None:
  41. db.execute(
  42. 'INSERT INTO user (first_name, last_name, type, username, password) VALUES (?, ?, ?, ?, ?)',
  43. (first_name, last_name, type_user, username, generate_password_hash(password))
  44. )
  45. db.commit()
  46. return redirect(url_for('auth.login'))
  47.  
  48. flash(error)
  49.  
  50. return render_template('auth/register.html')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement