Esempio n. 1
0
def login(request):
    email = request.POST['email']
    password = request.POST['passwd']
    try:
        user = User.objects.get(email = email)
        if not user.password == calc_md5(password):
            raise ValueError('password is incorrect')
    except:
        return HttpResponseBadRequest('login failed')
    response = redirect(reverse('wills:will_list', args=[user.id]))
    response.set_cookie('userid', user.id)
    return response
Esempio n. 2
0
def regist(request):
    pwd = request.POST.get('passwd')
    if not len(pwd.strip()) >= 6 or not len(pwd.strip()) <= 12:
        return HttpResponseBadRequest('password illegal')
    pwd = calc_md5(pwd)
    (user, first_create) = regist_user_email(request.POST.get('email'), 
            pwd)
    logger.info(user, first_create)
    logger.info(first_create)
    if not first_create:
        return HttpResponseBadRequest('the email is being used')
    response = redirect(reverse('wills:will_list', args=[user.id]))
    response.set_cookie('userid', user.id)
    return response