示例#1
0
def join_via_ref(request, ref_hash):
    joinForm = JoinForm()
    joinForm.fields['ref_hash'].initial = ref_hash
    userViaRef = GsuserManager.get_userViaRef_by_refhash(ref_hash)
    tip = ''
    if userViaRef:
        tip = userViaRef.ref_message
    if userViaRef and userViaRef.email:
        joinForm.fields['email'].initial = userViaRef.email
        joinForm.fields['username'].initial = userViaRef.email.split('@')[0]
    if userViaRef and userViaRef.username:
        joinForm.fields['username'].initial = userViaRef.username
    return _join(request, joinForm, 'ref', tip, '0')
示例#2
0
文件: views.py 项目: ZheYuan/gitshell
def join_via_ref(request, ref_hash):
    joinForm = JoinForm()
    joinForm.fields['ref_hash'].initial = ref_hash
    userViaRef = GsuserManager.get_userViaRef_by_refhash(ref_hash)
    tip = ''
    if userViaRef:
        tip = userViaRef.ref_message
    if userViaRef and userViaRef.email:
        joinForm.fields['email'].initial = userViaRef.email
        joinForm.fields['username'].initial = userViaRef.email.split('@')[0]
    if userViaRef and userViaRef.username:
        joinForm.fields['username'].initial = userViaRef.username
    return _join(request, joinForm, 'ref', tip, '0')
示例#3
0
文件: views.py 项目: ZheYuan/gitshell
def bind(request, ref_hash):
    userViaRef = None
    if ref_hash:
        userViaRef = GsuserManager.get_userViaRef_by_refhash(ref_hash)
        GsuserManager.handle_user_via_refhash(request.user, ref_hash)
    if userViaRef:
        is_verify = 1
        if userViaRef.ref_type == REF_TYPE.VIA_REPO_MEMBER:
            GsuserManager.add_useremail(request.user, userViaRef.email, is_verify)
            return HttpResponseRedirect('/%s/%s/' % (userViaRef.first_refname, userViaRef.second_refname))
        elif userViaRef.ref_type == REF_TYPE.VIA_TEAM_MEMBER:
            GsuserManager.add_useremail(request.user, userViaRef.email, is_verify)
            return HttpResponseRedirect('/%s/' % (userViaRef.first_refname))
    return HttpResponseRedirect('/dashboard/')
示例#4
0
文件: views.py 项目: ZheYuan/gitshell
def _join(request, joinForm, joinVia, tip, step):
    if step is None:
        step = '0'
    error = u''; title = u'注册'
    if step == '0' and request.method == 'POST':
        joinForm = JoinForm(request.POST)
        if joinForm.is_valid():
            email = joinForm.cleaned_data['email']
            username = joinForm.cleaned_data['username']
            password = joinForm.cleaned_data['password']
            ref_hash = joinForm.cleaned_data['ref_hash']
            user_by_email = GsuserManager.get_user_by_email(email)
            user_by_username = GsuserManager.get_user_by_name(username)
            if user_by_email is None and user_by_username is None:
                if ref_hash:
                    userViaRef = GsuserManager.get_userViaRef_by_refhash(ref_hash)
                    if userViaRef and _create_user_and_authenticate(request, username, email, password, ref_hash, True):
                        return HttpResponseRedirect('/join/3/')
                client_ip = _get_client_ip(request)
                cache_join_client_ip_count = cache.get(CacheKey.JOIN_CLIENT_IP % client_ip)
                if cache_join_client_ip_count is None:
                    cache_join_client_ip_count = 0
                cache_join_client_ip_count = cache_join_client_ip_count + 1
                cache.set(CacheKey.JOIN_CLIENT_IP % client_ip, cache_join_client_ip_count)
                if cache_join_client_ip_count < 10 and _create_user_and_authenticate(request, username, email, password, ref_hash, False):
                    return HttpResponseRedirect('/join/3/')
                Mailer().send_verify_account(email, username, password, ref_hash)
                goto = ''
                email_suffix = email.split('@')[-1]
                if email_suffix in COMMON_EMAIL_DOMAIN:
                    goto = COMMON_EMAIL_DOMAIN[email_suffix]
                return HttpResponseRedirect('/join/1/?goto=' + goto)
            error = u'欢迎回来, email: %s 或者 name: %s 已经注册过了, 您只需要直接登陆就行。' % (email, username)
        else:
            error = u'啊? 邮箱或验证码有误输入。注意大小写和前后空格。'
    if len(step) > 1:
        email = cache.get(step + '_email')
        username = cache.get(step + '_username')
        password = cache.get(step + '_password')
        ref_hash = cache.get(step + '_ref_hash')
        if email is None or username is None or password is None or not email_re.match(email) or not re.match("^[a-zA-Z0-9_-]+$", username) or username.startswith('-') or username in MAIN_NAVS:
            return HttpResponseRedirect('/join/4/')
        if _create_user_and_authenticate(request, username, email, password, ref_hash, True):
            return HttpResponseRedirect('/join/3/')
        else:
            error = u'啊? 用户名或密码有误输入,注意大小写和前后空格。'
    response_dictionary = {'step': step, 'error': error, 'title': title, 'joinForm': joinForm, 'joinVia': joinVia, 'tip': tip}
    return render_to_response('user/join.html',
                          response_dictionary,
                          context_instance=RequestContext(request))
示例#5
0
def bind(request, ref_hash):
    userViaRef = None
    if ref_hash:
        userViaRef = GsuserManager.get_userViaRef_by_refhash(ref_hash)
        GsuserManager.handle_user_via_refhash(request.user, ref_hash)
    if userViaRef:
        is_verify = 1
        if userViaRef.ref_type == REF_TYPE.VIA_REPO_MEMBER:
            GsuserManager.add_useremail(request.user, userViaRef.email,
                                        is_verify)
            return HttpResponseRedirect(
                '/%s/%s/' %
                (userViaRef.first_refname, userViaRef.second_refname))
        elif userViaRef.ref_type == REF_TYPE.VIA_TEAM_MEMBER:
            GsuserManager.add_useremail(request.user, userViaRef.email,
                                        is_verify)
            return HttpResponseRedirect('/%s/' % (userViaRef.first_refname))
    return HttpResponseRedirect('/dashboard/')
示例#6
0
def _join(request, joinForm, joinVia, tip, step):
    if step is None:
        step = '0'
    error = u''
    title = u'注册'
    if step == '0' and request.method == 'POST':
        joinForm = JoinForm(request.POST)
        if joinForm.is_valid():
            email = joinForm.cleaned_data['email']
            username = joinForm.cleaned_data['username']
            password = joinForm.cleaned_data['password']
            ref_hash = joinForm.cleaned_data['ref_hash']
            user_by_email = GsuserManager.get_user_by_email(email)
            user_by_username = GsuserManager.get_user_by_name(username)
            if user_by_email is None and user_by_username is None:
                if ref_hash:
                    userViaRef = GsuserManager.get_userViaRef_by_refhash(
                        ref_hash)
                    if userViaRef and _create_user_and_authenticate(
                            request, username, email, password, ref_hash,
                            True):
                        return HttpResponseRedirect('/join/3/')
                client_ip = _get_client_ip(request)
                cache_join_client_ip_count = cache.get(
                    CacheKey.JOIN_CLIENT_IP % client_ip)
                if cache_join_client_ip_count is None:
                    cache_join_client_ip_count = 0
                cache_join_client_ip_count = cache_join_client_ip_count + 1
                cache.set(CacheKey.JOIN_CLIENT_IP % client_ip,
                          cache_join_client_ip_count)
                if cache_join_client_ip_count < 10 and _create_user_and_authenticate(
                        request, username, email, password, ref_hash, False):
                    return HttpResponseRedirect('/join/3/')
                Mailer().send_verify_account(email, username, password,
                                             ref_hash)
                goto = ''
                email_suffix = email.split('@')[-1]
                if email_suffix in COMMON_EMAIL_DOMAIN:
                    goto = COMMON_EMAIL_DOMAIN[email_suffix]
                return HttpResponseRedirect('/join/1/?goto=' + goto)
            error = u'欢迎回来, email: %s 或者 name: %s 已经注册过了, 您只需要直接登陆就行。' % (
                email, username)
        else:
            error = u'啊? 邮箱或验证码有误输入。注意大小写和前后空格。'
    if len(step) > 1:
        email = cache.get(step + '_email')
        username = cache.get(step + '_username')
        password = cache.get(step + '_password')
        ref_hash = cache.get(step + '_ref_hash')
        if email is None or username is None or password is None or not email_re.match(
                email) or not re.match("^[a-zA-Z0-9_-]+$",
                                       username) or username.startswith(
                                           '-') or username in MAIN_NAVS:
            return HttpResponseRedirect('/join/4/')
        if _create_user_and_authenticate(request, username, email, password,
                                         ref_hash, True):
            return HttpResponseRedirect('/join/3/')
        else:
            error = u'啊? 用户名或密码有误输入,注意大小写和前后空格。'
    response_dictionary = {
        'step': step,
        'error': error,
        'title': title,
        'joinForm': joinForm,
        'joinVia': joinVia,
        'tip': tip
    }
    return render_to_response('user/join.html',
                              response_dictionary,
                              context_instance=RequestContext(request))