Commits

Yang Zhang  committed 5b05df5

user register finish

  • Participants
  • Parent commits 15d1a40

Comments (0)

Files changed (5)

     email               VARCHAR,
     password            VARCHAR,
     avatar              BLOB,-------- need to reduce
+    star_counter        INTEGER DEFAULT 0,
     create_date         TIMESTAMP DEFAULT (datetime('now','localtime')),
     reputation          INTEGER,
     UNIQUE(nickname),

File models/user.py

         self.password = not password or hashlib.sha224(password).hexdigest()
         self.create_date = None
         self.reputation = None
+        self.star_counter = 0
 
 
     @staticmethod

File templates/register.html

 {% block content %}
 
 <div id='signup' class='container'>
-    <form id='signup_form' class="container-box offset2 span8"method=post>
+    <form id='signup_form' class="container-box offset2 span8" method='post' >
     <legend>用户注册</legend>
     <table id='signuptable' class='offset2'>
         <tr>

File templates/widgets/user.html

         </a>
     </div>
     <div id='user-info' class='span7'>
-        <label>用户名</label>
-        <a href="#" title='收藏主题数'><i class="icon-star"></i> <small>111</small></a>
+        <label>{{user.nickname}}</label>
+        <a href="#" title='收藏主题数'><i class="icon-star"></i> <small>{{user.star_counter}}</small></a>
+        {#
         <a href="#" title='主题标签数'><i class="icon-bookmark"></i> <small>111</small></a>
+        #}
         <br/>
         <a href="#" title='发布新主题'><i class="icon-pencil"></i> <small>发布新主题</small></a>
     </div>
 
     <div class='span1'>
-        <a href="#" title='登出'><i class="icon-off"></i></a>
+        <a href="/logout" title='登出'><i class="icon-off"></i></a>
     </div>
 </div>
 {%else%}

File views/frontend.py

 from flask import Module, url_for, \
     redirect, g, flash, request, current_app,\
-    render_template
-
-
+    render_template, session
+from py4u.models import User
+from py4u.configure import configure
 frontend = Module(__name__)
 
+@frontend.context_processor
+def inject_configure():
+    return dict(configure.__dict__)
+@frontend.context_processor
+def inject_user():
+    user=session.get('user',None)
+    return dict(user = user)
 
 @frontend.route("/")
 @frontend.route("/hot")
         return render_template("register.html")
 
     elif request.method == 'POST':
-        return 'p'
+        #check if email or nickname exist
+        email = request.form['email']
+        nickname = request.form['nickname']
+        password = request.form['password']
+        user = User(email,nickname,password)
+        user.save()
+        session['user'] = user
+        return redirect(url_for('index'))
 
 
+@frontend.route("/logout")
+def logout():
+    if('user' in session):
+        session.pop('user')
+    return redirect(url_for('index', page = 1))
 
 
 
 
 
 
-