示例#1
0
def login():
    username = request.form['username']
    password = request.form['password']

    teacher = auth.authenticate(username, password)

    if teacher == False:
        return response_error('wrong_password')

    auth.login_user(teacher)

    return json.dumps({
        'response': 'success',
        'user': teacher.as_json()
    })
示例#2
0
def set_teacher_settings():
    user = auth.get_logged_in_user()

    fullname = request.form.get('fullname')
    old_password = request.form.get('old_password')
    new_password = request.form.get('new_password')
    email = request.form.get('email')

    if fullname:
        user.fullname = fullname

    if email:
        user.email = email

    if old_password and new_password:
        u = auth.authenticate(user.username, old_password)
        if not u:
            return response_error('wrong_old_password')

        user.set_password(new_password)

    user.save()

    return response_success()