Exemple #1
0
 def setUp(self):
     self.app = create_app('test')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
     self.client = self.app.test_client()
     tag = Tag()
     tag.name = 'tagx'
     db.session.add(tag)
     category = Category()
     category.name = 'categoryx'
     db.session.add(category)
     db.session.commit()
     article = Article()
     article.title = 'articlex'
     article.slug = 'slugx'
     article.category = category
     article.content = 'contentx'
     article.tags = [tag]
     db.session.add(category)
     db.session.commit()
     user = User()
     user.name = 'admin'
     user.password = '******'
     db.session.add(user)
     db.session.commit()
Exemple #2
0
    def post(self, request, *args, **kwargs):
        name = request.POST.get('name')
        pwd = request.POST.get('pwd')

        user = User()
        user.name = name
        user.pwd = encryption_md5(pwd)
        user.save()

        return redirect('/login')
Exemple #3
0
def search(request):
	if request.method == 'POST' :
		uf = UserForm1(request.POST)
		if uf.is_valid():
			username = uf.cleaned_data['username']
			print username
			user = User()
			user.name  =username
			book_list=User.objects.filter(name__istartswith = user.name)
			return render_to_response('search_form.html',{'uf':uf,'book_list':book_list})	
	else:
		uf = UserForm1()
	return render_to_response('search_form.html',{'uf':uf})
Exemple #4
0
def register(request):
	if request.method == "POST" :
		uf = UserForm(request.POST,request.FILES)
		if uf.is_valid():
			username = uf.cleaned_data['username']
			headImg  = uf.cleaned_data['headImg']
			user = User()
			user.name    =username
			user.headImg =headImg
			user.save()
			print username,headImg
			ua = request.META.get('HTTP_USER_AGENT', 'unknown')
			return HttpResponse("Your browser is %s" % ua)
	else :
		uf = UserForm()
	return render_to_response('register.html',{'uf':uf,'title':'baba'})
Exemple #5
0
def adduser():
    user = User()
    user.name = raw_input("Name: ")
    email = raw_input("Email: ")
    if email == session.query(User).filter(User.email==email).first():
        print "Someone's already registered with that email."
        return
    user.email = email  
    password = ""
    password2 = ""
    while not (password and password2) or password != password2:
        password = getpass("Password:"******"Repeat password:")
    user.password = generate_password_hash(password)
    session.add(user)
    session.commit()
Exemple #6
0
def regist(req):
    print req.method
    if req.method == "POST":
	uf = UserForm(req.POST, req.FILES)
        print 'valid? : ', uf.is_valid()
	if uf.is_valid():
	    print 'uf is valid'
	    user = User()
	    user.name =  uf.cleaned_data['username']
	    user.headImg = uf.cleaned_data['headImg']
	    user.save()
	    print user.name
	    return HttpResponse('ok')
    else:
	uf = UserForm()	    
    return render_to_response('register.html', {'uf':uf})
Exemple #7
0
def register(request):
    username = request.POST.get('usernameReg', '')
    password = request.POST.get('passwordReg', '')
    email = request.POST.get('emailReg', '')
    profilePhoto = request.POST.get('profilePhoto', '')
    articleid = request.POST.get('articleid', '')
    if username == '' or password == '' or email == '':
        message = '输入错误了,快说你是怎么进的这个页面!'
    else:
        if profilePhoto == '':
            profilePhoto = '/static/img/deafaultprofilePhoto.png'
        user = User()
        user.name = username
        user.password = password
        user.email = email
        user.profilePhoto = profilePhoto
        try:
            userInDB = User.objects.get(name=username)
        except:
            userInDB = None
        if userInDB:
            message = '非常抱歉,你已经注册过了!'
        else:
            user.save()
            message = '哈哈!注册成功了啦(原谅老夫的少女心)!'
            request.session['name'] = user.name
    article = Article.objects.get(id=articleid)
    articles = mdToHtml([article])
    try:
        comments = Comment.objects.filter(article=article)
        i = 1
        for comment in comments:
            comment.floor = i
            i += 1
    except:
        comments = None
    try:
        username = request.session.get('name')
        user = User.objects.get(name=username)
    except:
        username = None
        user = None
    comments = mdToHtml(comments)
    context = {'config': configList,
               'articles': articles, 'comments': comments, 'user': user, 'message': message}
    return render(request, 'blogs.html', context=context)
Exemple #8
0
def signin(request):
    if request.POST:
        adduser = User()
        adduser.name = request.POST['username']
        if (User.objects.filter(name=request.POST['username'])):
            msg = 'this name has existed,srory!try a good one!'
            return render(request, "signup.html", {'msg': msg})
        if request.POST['username'] in [
                'Username', 'username'
        ] and request.POST['password'] == 'password':
            msg = 'username can not be blank'
            return render(request, "signup.html", {'msg': msg})
        adduser.password = request.POST['password']
        adduser.save()
        msg = 'sign in ok,please log on!'
        return render(request, "logon.html", {'msg': msg})
    return render(request, "signup.html")