示例#1
0
def register(request):
    if request.method == 'POST':
        form = Register(request.POST, request.FILES)
        if form.is_valid():
            user = Libuser.objects.create(
                username=form.cleaned_data['username'],
                first_name=form.cleaned_data['first_name'],
                last_name=form.cleaned_data['last_name'],
                email=form.cleaned_data['email'],
                address=form.cleaned_data['address'],
                city=form.cleaned_data['city'],
                province=form.cleaned_data['province'],
                phone=form.cleaned_data['phone']
            )
            password = form.cleaned_data['password']
            user.profilepic = form.cleaned_data['profilepic']
            user.set_password(password)
            user.save()
            form = Register()
            return render(request, 'libapp/register.html', {'form': form, 'added': True})
        else:
            form = Register()
            return render(request, 'libapp/register.html', {'form': form, 'failed': True})
    else:
        form = Register()
        return render(request, 'libapp/register.html', {'form': form})
示例#2
0
def register(request):
    #insert cookie logic for persistence
    set_browser_session(request)
    if request.method == "POST":
        form = Register(request.POST)

        if form.is_valid():
            data = form.cleaned_data

            if db.no_user(data['username'], data['email_address']):
                #pr,pu = crypto.gen_key_pair()
                passwd = str(data['password'])
                key = crypto.key_from_pass(passwd, crypto.gen_salt(),
                                           crypto.ITER_100K, crypto.KEY_256)
                o = dict(data)
                o['secret'] = key
                o['otp_salt'] = crypto.gen_otp_secret()
                db.save_user(o)

                store = dict()
                store['site'] = "MABEBA Website"
                store['username'] = str(data['username'])
                store['token_url'] = PRODUCTION_URL + '/token/'
                store['secret'] = key
                store['otp_salt'] = o['otp_salt']

                salt = crypto.gen_salt()

                key = crypto.key_from_pass(passwd, salt, crypto.ITER_100K,
                                           crypto.KEY_256)
                key = crypto.key_to_bytes(key)

                encrypted = crypto.aes_encrypt(str(store), key)

                random_id = crypto.get_random_id()
                db.store_in_file(encrypted, random_id)

                o = dict()
                o['salt'] = salt
                o['token'] = PRODUCTION_URL + '/register/token/' + random_id
                o = json.dumps(o)
                print o

                data = qr_render(o)

                return render(request, 'app/qr.html', {'data': data})

            else:
                return do_register(request)

        else:
            return do_register(request)

    else:
        return do_register(request)
示例#3
0
def register(request):
    #insert cookie logic for persistence
    set_browser_session(request)
    if request.method == "POST":
        form = Register(request.POST)

        if form.is_valid():
            data = form.cleaned_data

            if db.no_user(data['username'],data['email_address']):
                #pr,pu = crypto.gen_key_pair()
                passwd = str(data['password'])
                key = crypto.key_from_pass(passwd,crypto.gen_salt(),crypto.ITER_100K,crypto.KEY_256)
                o = dict(data)
                o['secret'] = key
                o['otp_salt'] = crypto.gen_otp_secret()
                db.save_user(o)

                store = dict()
                store['site'] = "MABEBA Website"
                store['username'] = str(data['username'])
                store['token_url'] = PRODUCTION_URL + '/token/'
                store['secret'] = key
                store['otp_salt'] = o['otp_salt']

                salt = crypto.gen_salt()


                key = crypto.key_from_pass(passwd,salt,crypto.ITER_100K,crypto.KEY_256)
                key = crypto.key_to_bytes(key)

                encrypted = crypto.aes_encrypt(str(store),key)

                random_id = crypto.get_random_id()
                db.store_in_file(encrypted,random_id)

                o = dict()
                o['salt'] = salt
                o['token'] = PRODUCTION_URL + '/register/token/' + random_id
                o = json.dumps(o)
                print o

                data = qr_render(o)

                return render(request,'app/qr.html',{'data':data})

            else:
                return do_register(request)

        else:
            return do_register(request)


    else:
        return do_register(request)