Пример #1
0
def adm(subpath_adm):
  ls_adm = ls_path('admin')
  lst = ls_path('home')
  if get_admin(current_user.email) == True:
    return render_template('admin/%s.html' % (subpath_adm), 
      title='%s' % (subpath_adm), 
      fbase=ls_adm, 
      files=lst, 
      Course=Course,
      url=url, 
      list_rules=list_rules, 
      User=User, 
      Role=Role, 
      get_admin=get_admin, 
      get_tutor=get_tutor, 
      get_student=get_student )
  else:
    return render_template('errors_page/unauthorized.html',
    title='unauthorized',
    files=lst,
    Course=Course,
    url=url,
    get_admin=get_admin,
    get_tutor=get_tutor, 
    get_student=get_student)
Пример #2
0
def add_user():
  ls_adm = ls_path('admin')
  lst = ls_path('home')
  if not get_admin(current_user.email) == True:
    return render_template('errors_page/unauthorized.html',
      title='unauthorized',
      files=lst,
      Course=Course,
      url=url,
      get_admin=get_admin,
      get_tutor=get_tutor, 
      get_student=get_student)
  form = RegistrationForm()
  if form.validate_on_submit():
    user = User(username=form.username.data, email=form.email.data)
    user.set_password(form.password.data)
    db.session.add(user)
    db.session.commit()
    u = User.query.filter_by(email=form.email.data).first().id
    r = Role.query.filter_by(type='tutor').first().id
    a = UserRoles(user_id=u, role_id=r)
    db.session.add(a)
    db.session.commit()
    flash('Congratulations, registered a new user!')
    return redirect('/add_user')
  return render_template('add_user.html', 
    title='add a new user', 
    files=lst,
    fbase=ls_adm, 
    Course=Course,
    User=User, 
    Role=Role, 
    UserRoles=UserRoles,
    form=form,
    get_admin=get_admin, 
    get_tutor=get_tutor, 
    get_student=get_student)
Пример #3
0
def login():
  lst = ls_path('home')
  form = LoginForm()
  if form.validate_on_submit():
    user = User.query.filter_by(email=form.username.data).first()
    if user is None or not user.check_password(form.password.data):
      flash('Invalid username or password')
      return redirect( "/login" )
    login_user(user, remember=form.remember_me.data)
    if get_admin(current_user.email) == True:
      return redirect('/admin/roles')
    elif get_student(current_user.email) == True:
      return redirect('/student/my_curses')
    elif get_tutor(current_user.email) == True:
      return redirect('/tutor/my_classes')
  return render_template( 'login.html', 
    title='login', 
    files=lst, 
    Course=Course,
    url=url, 
    form=form, 
    get_admin=get_admin, 
    get_tutor=get_tutor, 
    get_student=get_student)
def get_users():
    if get_admin(get_jwt_identity()) or get_tutor(get_jwt_identity()):
        return jsonify(getUsers()), 200
    else:
        return jsonify({"msg": "not authorized"}), 401
def register_tutor():
    if get_admin(get_jwt_identity()):
        return register('tutor'), 200
    else:
        return jsonify({"msg": "not authorized"}), 401