Example #1
0
def login(request):
    if not request.user.is_authenticated():
        next=''
        if request.GET.get('next'):
            next='?next='+request.GET.get('next')
        if request.method == 'POST':
            form = LoginForm(request.POST)
            e=form.errors
            if form.is_valid():
                username = request.POST.get('username', '')
                password = request.POST.get('password', '')
                user = auth.authenticate(username=username, password=password)
                if user is not None and user.is_active:
                    auth.login(request, user)
                    return redirect(request,URL_PRE+"/")
                else:
                    return render_form_page(request,next,'login.html',LoginForm,error={'pwd_wrong':True})
        return render_form_page(request,next,'login.html',LoginForm)
    else:
        return redirect(request,URL_PRE+"/")
Example #2
0
def edit_profile(request):
    error={}
    if request.method == 'POST':
        form = EditProfileForm(request.POST)
        if form.is_valid():
            email,nickname = request.POST.get('email'),request.POST.get('nickname')
            user = request.user
            user.email,user.nickname = email,nickname
            user.save()
            error={'edit_success':True}

    return render_form_page(request,'','edit-profile.html',EditProfileForm,{'email':request.user.email,'nickname':request.user.nickname},error)
Example #3
0
def passwd(request):
    error={}
    if request.method == 'POST':
        form = PasswdForm(request.POST)
        if form.is_valid():
            user = request.user
            if user.check_password(request.POST.get('ori_password')):
                passwd = request.POST.get('password')
                user.set_password(passwd)
                user.save()
                error={'edit_success':True}
            else:
                return HttpResponse("wrong password")
    return render_form_page(request,'','passwd.html',PasswdForm,{},error)
Example #4
0
def useradd(request):
    if in_admin_group(request.user):
        error={}
        if request.method == 'POST':
            form = UseraddForm(request.POST)
            if form.is_valid():
                post_data=form.cleaned_data
                username,pw,email,nickname = post_data['username'],post_data['password'],post_data['email'],post_data['nickname']
                try:
                    user = Member.objects.create_user(username, email, pw)
                    user.nickname=nickname
                    uaddon = MemberAddon(mid=user.id)
                    user.save()
                    uaddon.save()
                    return redirect(request,'/wheel/')
                except:
                    error['name_wrong']=True#实际上也可能会是邮箱出错
        return render_form_page(request,'','wheel/useradd.html',UseraddForm,{},error)
    else:
        return HttpResponseRedirect('/')