Beispiel #1
0
def signup(request):
    '''
    User signup.
    
    *URL Name* - ``signup``.
    
    *POST Parameters*
    
      ``email`` - The user's email address.
    
    *URL Name* - ``user-signup``.

    *Template Name* - ``signup.html``.
    '''
    if request.method == 'POST':
        email = request.POST.get('email', None)
        if not email:
            messages.error(request, u'请输入电子邮箱!')
        elif not is_valid_email(email):
            messages.error(request, u'电子邮箱格式不正确!')
        else:
            user = get_or_none(User, email=email)
            if user:
                messages.error(request, u'账号已存在,请登录或使用另一个电子邮箱')
            else:
                username = _generate_username()
                user = User(email=email, username=username)
                user.save()
                confirm_code = user.get_profile().confirm_code
                confirm_link = reverse('user-confirm-signup',
                                       args=[confirm_code])
                send_email(email,
                           'signup',
                           context=dict(confirm_link=confirm_link))
                messages.success(
                    request,
                    _('Registratoin submitted! Check your email to for further instructions.'
                      ))
    else:  # request.method is "GET"
        if request.user.is_authenticated():
            return redirect(request.POST.get('next', '/'))

    return render_to_response('users/signup.html',
                              context_instance=RequestContext(request))
Beispiel #2
0
def signin(request):
    '''
    User signin.
    
    *POST Parameters*
    
      ``username`` - The username or email address.

      ``password`` - The password.

      ``code`` - CAPTCHA code, TODO
    
    *URL Name* - ``signin``.
    
    *Template Name* - ``signin.html``.
    '''
    if request.method == 'POST':
        username = request.POST.get('username', None)
        password = request.POST.get('password', None)
        if not (username and password):
            messages.error(request, u'登录信息不完整!')
        else:
            if is_valid_email(username):
                found = get_or_none(User, email=username)
                if found:
                    username = found.username
            user = authenticate(username=username, password=password)
            if user:
                if user.is_active:
                    login(request, user)
                    return redirect(request.POST.get('next', '/'))
                else:
                    messages.error(request, u'账号被锁定,无法登录!')
            else:
                messages.error(request, u'登录信息不正确!')
    else:  # request.method is "GET"
        if request.user.is_authenticated():
            return redirect(request.POST.get('next', '/'))

    return render_to_response('users/signin.html',
                              context_instance=RequestContext(request))
Beispiel #3
0
def signin(request):
    '''
    User signin.
    
    *POST Parameters*
    
      ``username`` - The username or email address.

      ``password`` - The password.

      ``code`` - CAPTCHA code, TODO
    
    *URL Name* - ``signin``.
    
    *Template Name* - ``signin.html``.
    '''
    if request.method == 'POST':
        username = request.POST.get('username', None)
        password = request.POST.get('password', None)
        if not (username and password):
            messages.error(request, u'登录信息不完整!')
        else:
            if is_valid_email(username):
                found = get_or_none(User, email=username)
                if found:
                    username = found.username
            user = authenticate(username=username, password=password)
            if user:
                if user.is_active:
                    login(request, user)
                    return redirect(request.POST.get('next', '/'))
                else:
                    messages.error(request, u'账号被锁定,无法登录!')
            else:
                messages.error(request, u'登录信息不正确!')
    else: # request.method is "GET"
        if request.user.is_authenticated():
            return redirect(request.POST.get('next', '/'))

    return render_to_response('users/signin.html', context_instance=RequestContext(request))
Beispiel #4
0
def signup(request):
    '''
    User signup.
    
    *URL Name* - ``signup``.
    
    *POST Parameters*
    
      ``email`` - The user's email address.
    
    *URL Name* - ``user-signup``.

    *Template Name* - ``signup.html``.
    '''
    if request.method == 'POST':
        email = request.POST.get('email', None)
        if not email:
            messages.error(request, u'请输入电子邮箱!')
        elif not is_valid_email(email):
            messages.error(request, u'电子邮箱格式不正确!')
        else:
            user = get_or_none(User, email=email)
            if user:
                messages.error(request, u'账号已存在,请登录或使用另一个电子邮箱')
            else:
                username = _generate_username()
                user = User(email=email, username=username)
                user.save()
                confirm_code = user.get_profile().confirm_code
                confirm_link = reverse('user-confirm-signup', args=[confirm_code])
                send_email(email, 'signup', context=dict(confirm_link=confirm_link))
                messages.success(request, _('Registratoin submitted! Check your email to for further instructions.'))
    else: # request.method is "GET"
        if request.user.is_authenticated():
            return redirect(request.POST.get('next', '/'))
    
    return render_to_response('users/signup.html', context_instance=RequestContext(request))