Esempio n. 1
0
def uc_basicinfo(request, edit_profile_form=EditProfileForm):
    personal_user = None
    try:
        print request.user
        personal_user = AccountProfile.objects.get(user = request.user)

    except:
        # FIXME - I suppose exception only happen for not existed case
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        print info
        personal_user = AccountProfile(user = request.user,
                mail_act = 'blank')
        personal_user.save()

    form = edit_profile_form(instance = personal_user,initial={})

    if request.method == 'POST':
        form = edit_profile_form(request.POST, request.FILES, instance=personal_user,
                                 initial={})

        if form.is_valid():
             form.save()
        else :
             print form

    return render_to_response('uc_basic_info.html',
                { 
                    'form': form,
                     "user_name": request.user.username,
                    }, context_instance=RequestContext(request))
Esempio n. 2
0
def uc_reg(request):
    if request.method == 'POST':
        print 'POST'
        usr = AccountForm(request.POST)
        if usr.is_valid():
            name = usr.cleaned_data['user_name']
            passwd = usr.cleaned_data['password']
            print name
            print passwd
            if is_valid_email(name) == 1:
                print 'This is an email, status SHOULD NOT active until user clicked ths url'
                ticket = send_activation_mail(request.META['HTTP_HOST'], name)
                obj = User.objects.create_user(
                        username = name,
                        password=passwd,
                        email = name,
                        is_active = 0)
                obj.save()
                obj = User.objects.get(username=name)
                uid = obj.id
                print 'the user id is %d' %(uid)
                prof_obj = AccountProfile(user_id = uid,
                        mail_act = ticket)
                prof_obj.save()
            else:
                print 'a normal user, can directly saving'
                # Now save the Data into DB...
                obj = User.objects.create_user(
                        username = name, password=passwd)

                obj.save()

            # TODO reg OK should NOT return below HTML UI
            return render_to_response('regok.html', {'user':usr})
    else:
        ticket = request.GET.get('ticket')
        print ticket
        email = request.GET.get('user')
        print email
        if ticket != None and email != None:
            return activate_email_account(
                    ticket,
                    email)
        else:
            usr = AccountForm()
    return render_to_response('reg.html', {'user':usr})