Beispiel #1
0
def create_avatar(name,pwd,ip):
    """
    创建用户
    """
    print("name:%s"%name)
    print("pwd:%s"%pwd)
    if name and pwd:  
        if isinstance(name, str):
            name = name.decode('utf-8')
        assert len(name.decode()) <= 10,'用户名长度最多为10'
        assert is_other(uniform(name)) == False,'用户名只能为中文,数字,英文'
        if isinstance(pwd, str):
            pwd = pwd.decode('utf-8')
        assert len(pwd.decode()) <= 10,'密码长度最多为10'
        assert is_num_str(pwd) == True,'密码只能为英文,数字'
        avatar['name'] = name
        avatar['password'] = md5_str(name)
        avatar['register_info']['register_ip'] = ip
        avatar['last_login_ip'] = ip
    else:
        print '>>>>>>>>>>>>>>>>>>>用户名或者密码为空!!!!!!!!!!!!!!'
Beispiel #2
0
def create_new_user(request):
    """
    注册
    """
    user_session =request.session 
    ip = request.META['REMOTE_ADDR']
    username = request.POST.get('username','').strip()
    password = request.POST.get('password','').strip()
    return_url = request.session['return_url']
    rname = deepcopy(request.POST.get('username',''))
    print 'return_url  url:',request.session['return_url']
    print 'username:'******'password:'******'name res:',chars.is_valid_user_name(username_unicode),len(username_unicode)
        print 'pwd res:',chars.is_num_str(password_unicode),len(password_unicode)
        if chars.is_valid_user_name(username_unicode) == False :
            print '用户名字符不对'
            request.session['error_input']='用户名'
            request.session['error_reason']='用户名只能是英文数字或中文!'
        elif len(username_unicode)>8:
            print '用户名长度不对'
            request.session['error_reason']='用户名长度最多8位!'
            request.session['error_input']='用户名'
        #检测用户名合法性,只能是1-6位的数字英文
        if chars.is_num_str(password_unicode) == False :
            print '密码字符不对'
            request.session['error_reason']='密码只能为英文或数字'
            request.session['error_input']='密码'
        elif len(password_unicode)<6:
            print '密码长度不对'
            request.session['error_reason']='密码长度至少需要6位!'
            request.session['error_input']='密码'

        if request.session.get('error_input',''):
            request.session['username_input_error']=username
            request.session['last_request']='create_user'
            return  HttpResponseRedirect('/register')

        uid = mdb.create_user(username,password,ip)
        print 'uid:',uid
        return_path = return_url.split('/',3)[-1]
        if uid:
            #用户名是否已存在
            #print 'return  path:',return_path
            if return_path.replace('/','') in ('register','logout','userlogin'):
                return_url = '/'
            else:
                return_url = '/'+return_path
            request.session['is_login']=1
            request.session['name']=username
            request.session['uid']=uid
            #print 'return url:',return_url
            response  = render_to_response('info.html', {'content':"注册成功!",'title':'注册成功','return_url':return_url}) 
            print 'cookie name:',username
            #response.set_cookie("username",repr(rname))
            #response.set_cookie("username",username)
            return response
        else:
            request.session['error_reason']='用户名已存在'
            request.session['error_input']='用户名'
            request.session['username_input_error']=username
            request.session['last_request']='create_user'
            return  HttpResponseRedirect('/register')
    else:
        request.session['error_reason']=''
        request.session['error_input']='用户名和密码不能为空'
        request.session['username_input_error']=username
        request.session['last_request']='create_user'
        return  HttpResponseRedirect('/register')