Beispiel #1
0
def get_school(user):
    """
    获取老师或学生的学校
    """
    if is_teacher(user):
        return user.teacher.school
    if is_student(user):
        return user.student.school
    return None
Beispiel #2
0
def get_name(user):
    """
    获取老师或学生的姓名
    """
    if is_teacher(user) and user.teacher.name:
        return user.teacher.name
    if is_student(user) and user.student.name:
        return user.student.name
    try:
        return user.profile.chinese_name_or_username()
    except:
        return ''
Beispiel #3
0
def account_setting(request, template_name="oa/account_setting.html"):
    """个人设置"""
    if request.method == 'POST':
        password = request.user.password
        form1 = TeacherUserForm(request.POST,instance=request.user)
        form2 = UserProfileForm(request.POST, request.FILES,instance=request.user.get_profile())
        
        if form1.is_valid() and form2.is_valid():
            u = form1.save(commit=False)
            u.password = password
            u.save()
            profile = form2.save(commit=False)
            realname = request.POST['realname']
            profile.realname = realname
            profile.save()
            if helpers.is_teacher(request.user):
                teacher = request.user.teacher
                teacher.name = profile.realname
                teacher.save()
            if helpers.is_student(request.user):
                student = request.user.student
                student.name = profile.realname
                student.save()
            
            messages.success(request, _('Your profile has been updated.'))
            return redirect("oa_account_setting")
    else:
        form1 = TeacherUserForm(instance=request.user)
        form2 = UserProfileForm(instance=request.user.get_profile())
    
    
    try:
        postjob = request.user.teacher.postjob
    except:
        postjob = None
    ctx = {'form1': form1,'form2': form2,'postjob':postjob}
    ctx.update(csrf(request))
    return render(request, template_name, ctx)
Beispiel #4
0
def cross_domain_login(request):
    uid = request.GET.get('uid','')
    salt = request.GET.get('salt','')
    hash = request.GET.get('hash','')
    mask = '3n7j6m9s'
    m = md5.new(str(uid) + str(salt) + mask)
    new_hash = m.hexdigest()
    
    if new_hash == hash:
        user = User.objects.get(pk=uid)
        user.backend = 'django.contrib.auth.backends.ModelBackend'
        user.save()
#        user = auth.authenticate(username=u.username, password=u.password)
        is_teacher = helpers.is_teacher(user)
        is_student = helpers.is_student(user)
        if user is not None and user.is_active:
            auth.login(request, user)
    
        d = json.dumps({'is_teacher':is_teacher,'is_student':is_student,\
                        'username':helpers.get_name(user)})
#        request.GET['callback']+"("+(d)+");"
        return HttpResponse(request.GET['callback']+"("+(d)+");")
    else:
        return HttpResponse(json.dumps({}))