def register(): if(request.method == 'GET'): return render_template('register.html') error = False email = request.form.get('email',None) or None if email is None: flash(u'请输入Email地址','error') error = True if(User.is_email_exist(email)): flash(u'该Email已经注册','error') error = True nickname = request.form.get('nickname',None) or None if nickname is None: flash(u'请输入你的昵称','error') error = True if(User.is_nickname_exist(nickname)): flash(u'该昵称已经注册','error') error = True password = request.form.get('password',None) or None if password is None: flash(u'请输入你的密码','error') error = True if(error): return redirect(url_for('register')) user = User(email=email,nickname=nickname, password=sha224(password)) user.save() flash(u'注册成功','info') session['user'] = user return redirect(url_for('main'))
def tweet(self): from message import NotifyMessage nicknames = find_all_at_users(self.content) self.save() for nickname in nicknames: receiver = User.get_user_by_nickname(nickname) if receiver is not None: NotifyMessage.add(self.notify_render(),self.poster,receiver)
def show_user_followed_users(): userid = request.args.get("userid",None) user = User.get_user_by_id(userid) followed_users = Follow.get_followed_users_by_user(user) return render_template("show_followed_users.html", followed_users=followed_users, theuser=user)
def username_startwith(): startname = request.values.get("startwith", "") users = User.get_users_startwith(startname) return jsonify(users=[{ 'nickname': x.nickname, 'id': str(x.id), 'avatar': x.avatar } for x in users])
def add(cls,content,tweet,commenter): c = Comment(content=content, tweet=tweet, commenter=commenter) c.save() from message import NotifyMessage nicknames = find_all_at_users(c.content) for nickname in nicknames: receiver = User.get_user_by_nickname(nickname) NotifyMessage.add(c.notify_render(),c.commenter,receiver) return c
def add(cls, content, tweet, commenter): c = Comment(content=content, tweet=tweet, commenter=commenter) c.save() from message import NotifyMessage nicknames = find_all_at_users(c.content) for nickname in nicknames: receiver = User.get_user_by_nickname(nickname) NotifyMessage.add(c.notify_render(), c.commenter, receiver) return c
def register(): if (request.method == 'GET'): return render_template('register.html') error = False email = request.form.get('email', None) or None if email is None: flash(u'请输入Email地址', 'error') error = True if (User.is_email_exist(email)): flash(u'该Email已经注册', 'error') error = True nickname = request.form.get('nickname', None) or None if nickname is None: flash(u'请输入你的昵称', 'error') error = True if (User.is_nickname_exist(nickname)): flash(u'该昵称已经注册', 'error') error = True password = request.form.get('password', None) or None if password is None: flash(u'请输入你的密码', 'error') error = True if (error): return redirect(url_for('register')) user = User(email=email, nickname=nickname, password=sha224(password)) user.save() flash(u'注册成功', 'info') session['user'] = user return redirect(url_for('main'))
def login(): if (request.method == "GET"): return render_template('login.html') email = request.form.get('email', "") password = sha224(request.form.get('password', "")) user = User.validate_user(email, password) if (user is not None): session['user'] = user flash(u'登入成功', 'info') return redirect(url_for('main')) else: flash(u'登入失败, 请重试', 'error') return redirect(url_for('login'))
def login(): if(request.method == "GET"): return render_template('login.html') email = request.form.get('email',"") password = sha224(request.form.get('password',"")) user = User.validate_user(email, password) if(user is not None): session['user'] = user flash(u'登入成功','info') return redirect(url_for('main')) else: flash(u'登入失败, 请重试','error') return redirect(url_for('login'))
def basic_setting(): original_password = request.form.get("original_password", "") user = session['user'] error = False if user.password != sha224(original_password): flash(u"用户ID与密码不匹配",'error') return redirect(url_for("setting_view")) email = request.form.get("email", None) or None if email is None: flash(u'请输入Email地址','error') error = True if(user.email!=email and User.is_email_exist(email)): flash(u'该Email已经注册','error') error = True nickname = request.form.get('nickname',None) or None if nickname is None: flash(u'请输入你的昵称','error') error = True if(user.nickname!=nickname and User.is_nickname_exist(nickname)): flash(u'该昵称已经注册','error') error = True if error: return redirect(url_for("setting_view")) new_pwd = request.form.get("new_password") user.email = email user.nickname = nickname if new_pwd: user.password = sha224(new_pwd) user.save() flash(u"修改成功",'info') session['user'] = user return redirect(url_for("setting_view"))
def personal_center(userid=None): theuser = None if userid is None: theuser = session['user'] else: theuser = User.get_user_by_id(userid) page = request.args.get("page", 1, type=int) tweets = Tweet.get_users_tweets(theuser,offset=page-1,limit=15) return render_template("personal_center.html", theuser=theuser, tweets=tweets, more_url = url_for("personal_center",page=page+1,userid=userid) )
def test_nickname_exist(self): ok_(User.is_nickname_exist("12")) ok_(not User.is_nickname_exist("e1"))
def test_email_exist(self): ok_(User.is_email_exist("fake")) ok_(not User.is_email_exist("fake1"))
def test_get_user_by_id(self): user = User.get_user_by_id(self.user.id) eq_(user,self.user)
def test_auth(self): ok_(User.is_valid("fake",sha224("fakeone"))) user = User.validate_user("fake",sha224("fakeone")) eq_(user.nickname,self.user.nickname)
def tearDown(self): User.drop_collection() PrivateMessage.drop_collection()
def tearDown(self): User.drop_collection() NotifyMessage.drop_collection()
def show_user_by_nickname(nickname): userid = User.get_user_by_nickname(nickname).id return redirect(url_for("personal_center", userid=userid))
def username_startwith(): startname = request.values.get("startwith", "") users = User.get_users_startwith(startname) return jsonify(users=[{'nickname':x.nickname, 'id':str(x.id), 'avatar':x.avatar} for x in users])
def user_create(email, nickname, pw): return User(email=email, nickname=nickname, password=sha224(pw)).save()
def tearDown(self): User.drop_collection() PrivateMessage.drop_collection()
def tearDown(self): User.drop_collection() Follow.drop_collection()
def test_get_users_startwith(self): user = User.get_users_startwith("1")[0] eq_(user,self.user)
def toggle_follow(): followeduserid = request.form['followeduserid'] Follow.toggle_follow(session['user'], User.get_user_by_id(followeduserid)) return jsonify(result="done")
def test_get_user_by_nickname(self): user = User.get_user_by_nickname("12") eq_(user,self.user)
def show_user_by_nickname(nickname): userid = User.get_user_by_nickname(nickname).id return redirect(url_for("personal_center",userid=userid))
def tearDown(self): User.drop_collection() Tweet.drop_collection() Comment.drop_collection() NotifyMessage.drop_collection()
def tearDown(self): User.drop_collection() NotifyMessage.drop_collection()