Commits

Benoit Chesneau  committed 01a9a3f

add claim feature. started subdomain management

  • Participants
  • Parent commits 6d4e0a2

Comments (0)

Files changed (9)

File couchit/application.py

                 max_age = settings.SESSION_COOKIE_AGE
                 expires = time.time() + settings.SESSION_COOKIE_AGE
             session_store.save(request.session)
-            response.set_cookie(settings.SESSION_COOKIE_NAME, 
-                        request.session.sid, 
-                        expires=expires, max_age = max_age,
-                        path=settings.SESSION_COOKIE_PATH, 
-                        domain=settings.SESSION_COOKIE_DOMAIN, 
-                        secure=settings.SESSION_COOKIE_SECURE)
+            response.set_cookie(
+                settings.SESSION_COOKIE_NAME, 
+                request.session.sid, 
+                expires=expires, max_age = max_age,
+                path=settings.SESSION_COOKIE_PATH, 
+                domain=settings.SESSION_COOKIE_DOMAIN, 
+                secure=settings.SESSION_COOKIE_SECURE
+            )
 
         
         return response(environ, start_response)

File couchit/http.py

             self.session = session_store.new()
         else:
             self.session = session_store.get(self.sid)
+
+            
+            

File couchit/urls.py

 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from werkzeug.routing import Map, Rule, RequestRedirect,Submount
+from werkzeug.routing import Map, Rule, Subdomain, RequestRedirect,Submount
 
 from couchit import views
 
     'site_settings': views.site_settings,
     'site_claim': views.site_claim,
     'proxy': views.proxy,
+    'login': views.site_login,
+    'logout': views.site_logout
 }
 
 
     Rule('/<cname>/site/settings', endpoint='site_settings'),
     Rule('/<cname>/site/changes', endpoint='site_changes'),
     Rule('/<cname>/site/changes.<feedtype>', endpoint='site_changes'),
+    Rule('/<cname>/login', endpoint='login'),
+    Rule('/<cname>/logout', endpoint='logout'),
     Rule('/<cname>/<pagename>/revisions.<feedtype>', endpoint='revisions_feed'),
     Rule('/<cname>/<pagename>/revision/<nb_revision>', endpoint='revision_page'),
     Rule('/<cname>/<pagename>/history', endpoint='history_page'),
     Rule('/<cname>/<pagename>/diff', endpoint='diff_page'),
     Rule('/<cname>', defaults={'pagename': 'home' }, endpoint='show_page'),
     Rule('/<cname>/<pagename>', endpoint='show_page'),
+    Subdomain('<cname>',[
+        Rule('/', defaults={'pagename': 'home' }, endpoint='show_page'),
+        Rule('/proxy', endpoint='proxy'),
+        Rule('/site/design', endpoint='site_design'),
+        Rule('/site/claim', endpoint='site_claim'),
+        Rule('/site/settings', endpoint='site_settings'),
+        Rule('/site/changes', endpoint='site_changes'),
+        Rule('/site/changes.<feedtype>', endpoint='site_changes'),
+        Rule('/login', endpoint='login'),
+        Rule('/logout', endpoint='logout'),
+        Rule('/<pagename>/revisions.<feedtype>', endpoint='revisions_feed'),
+        Rule('/<pagename>/revision/<nb_revision>', endpoint='revision_page'),
+        Rule('/<pagename>/history', endpoint='history_page'),
+        Rule('/<pagename>/edit', endpoint='edit_page'),
+        Rule('/<pagename>/diff', endpoint='diff_page'),
+        Rule('/<pagename>', endpoint='show_page'),
+    ])
 ])

File couchit/views.py

     return render_response('home.html')
   
 @site_required  
-def show_page(request, cname=None, pagename=None):
+def show_page(request, cname=None, pagename=None, alias=None):
+    print alias
     if pagename is None:
         pagename ='home'
     page = get_page(local.db, request.site.id, pagename)
     
 @site_required
 def site_changes(request, cname, feedtype=None):
-    
     pages = all_pages(local.db, request.site.id)
     changes = get_changes(local.db, request.site.id)
 
     
 @site_required
 def site_claim(request, cname):
-    password=''
-    if request.method == "POST" and "spassword" in request.form:
-        password = request.form['password']
-    elif request.method == "POST":
+    if request.method == "POST":
+        site = get_site(local.db, cname)
         site.password = make_hash(request.form['password'])
         site.email = request.form['email']
         site.privacy = request.form['privacy']
         site.claimed = True
         site.store(local.db)
+        request.site = site
+        
+        request.session['%s_authenticated' % site.cname] = True;
         return redirect('/%s' % site.cname)
         
-    return render_response('site/claim.html', site=request.site, password=password)
+    return render_response('site/claim.html')
     
 @site_required
 def site_settings(request, cname):
     return render_response('site/settings.html', site=request.site)
+
+@site_required    
+def site_login(request, cname):
+    pass
+    
+@site_required
+def site_logout(request, cname):
+    request.session['%s_authenticated' % cname] = False
+    return redirect(request.url)
     
 @site_required
 def site_design(request, cname):

File static/css/src/layout.css

 
 
 
+
 #pdiff h4 {
     border-bottom: 1px solid;
 }
     overflow: auto;
 }
 
-.claim { 
-    float: right; 
-    display: block;
-    margin-right: 2.5em;
-    margin-bottom: 15px;
-    background-image: url("../../img/roundedcorners.svg"); 
-   	-moz-border-radius-bottomleft: 5px;
-    -moz-border-radius-bottomright: 5px;
-    -khtml-border-bottom-left-radius: 5px;
-    -webkit-border-bottom-left-radius: 5px;
-    -khtml-border-bottom-right-radius: 5px;
-    -webkit-border-bottom-right-radius: 5px;
-    border-bottom-left-radius: 5px;
-    border-bottom-right-radius: 5px;
-    padding: 5px;
-    
-    
-}
 
 
 /* window */
 tr.base .last {
     border-bottom: 1px solid;
 }
+
+tr.errors {
+    padding: 0.3em;
+    border: 1px solid;
+}
+
+div.help_error { display: block; font-weight: bold; font-size: 83%; width: 100%; position: relative; }
+
+/* claim */
+
+.claim, .logout { 
+    float: right; 
+    display: block;
+    margin-right: 2.5em;
+    margin-bottom: 15px;
+    background-image: url("../../img/roundedcorners.svg"); 
+   	-moz-border-radius-bottomleft: 5px;
+    -moz-border-radius-bottomright: 5px;
+    -khtml-border-bottom-left-radius: 5px;
+    -webkit-border-bottom-left-radius: 5px;
+    -khtml-border-bottom-right-radius: 5px;
+    -webkit-border-bottom-right-radius: 5px;
+    border-bottom-left-radius: 5px;
+    border-bottom-right-radius: 5px;
+    padding: 5px;
+    
+    
+}
+
+#claim_wrapper {
+    display: block;
+    width: 550px;
+    margin: 0 auto 0 auto;
+    padding: 10px;
+    border: 4px solid;
+    background-image: url(../../images/roundedcorners.svg);
+    -moz-border-radius: 5px;
+    -khtml-border-radius: 5px;
+    -webkit-radius: 5px;
+    border-radius: 5px;
+}
+
+
+

File static/css/src/slate.css

     border-bottom-color: #d4d4d4;
 }
 
-#phistory, #pdiff, #pdesign {
+#phistory,
+#pdiff,
+#pdesign,
+#claim_wrapper {
     background-color: #fff;
     border-color: #d4d4d4;
     color: #000;
     border-bottom-color: #33aa33;
 }
 
-.claim {
+.claim, .logout {
     background-color: #000;
     color: #fff;
 }
+
+tr.errors {
+    background: #ff9898;
+    border: #ff0000;
+}
+

File static/js/src/application.js

          }
         });
     }
+});
+
+var Claim = Class.create({
+    initialize: function() {
+        var self = this;
+        this.email = $('email');
+        this.password = $('password')
+        $('fclaim').observe('submit', function(e) {
+            Event.stop(e);
+            if (self.validate()) {
+                this.submit();
+            }
+        }, false);
+    },
+    
+    validate: function() {
+        $$('.help_error').each(function(el) {
+            el.remove();
+        });
+        $$('.errors').each(function(el) {
+            el.removeClassName('errors');
+        });
+        nb_errors = 0;
+        if (!this.email.value.match(/(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*")@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}$/i)) {
+            var div = new Element('div', {'class': 'help_error'}).update('Invalid email address.');
+            this.email.parentNode.insert(div);
+            $('row_email').addClassName('errors');
+            nb_errors += 1;
+        } 
+                
+        if (this.password.value.length <= 0) {
+            var div = new Element('div', {'class': 'help_error'}).update('You should set a password.');
+            this.password.parentNode.insert(div);
+            $('row_password').addClassName('errors');
+            nb_errors += 1;
+        }
+        
+        if (nb_errors > 0)
+            return false;
+        return true;
+        
+    }
 })
 
 

File templates/base.html

 body{background-color:#{{ site.theme.background_color }};color:#{{ site.theme.text_color }};}
 a{color:#{{ site.theme.link_color }};}
 #page article, #pedit #pedit_wrapper{background-color:#{{ site.theme.page_fill_color }};border-right-color:#{{ site.theme.border_color }};border-left-color:#{{ site.theme.border_color }};border-bottom-color:#{{ site.theme.border_color }};color:#{{ site.theme.page_text_color }};}
-#phistory,#pdiff,#pdesign,#pedit{background-color:#{{ site.theme.page_fill_color }};border-color:#{{ site.theme.border_color }};color:#{{ site.theme.page_text_color }};}
-#phistory,#pdiff,#pdesign,#page{color:#{{ site.theme.page_text_color }};}
+#phistory,#pdiff,#pdesign,#pedit,#claim_wrapper{background-color:#{{ site.theme.page_fill_color }};border-color:#{{ site.theme.border_color }};color:#{{ site.theme.page_text_color }};}
+#phistory,#pdiff,#pdesign,#page,#claim_wrapper{color:#{{ site.theme.page_text_color }};}
 #phistory a, #pdiff a, #pdesign a, #page a{color:#{{ site.theme.page_link_color }};}
 ul.subsection_tabs{background-color:#{{ site.theme.border_color }};}
 ul.subsection_tabs li.tab a, ul.subsection_tabs li.tab a:visited{color:#{{ site.theme.menu_inactive_color }};}
         
         <footer class="footer_wrapper">
             {% block footer %}{% endblock %}
-            <p>Powered by <a href="http://couchit.net">CouchIt</a></p>
+            <p>Powered by <a href="http://couch.it">CouchIt</a></p>
         </footer>
         
     </div>

File templates/site/claim.html

 {% block header %}{% endblock %}
 
 {% block fullpage %}
-<div id="claim-wrapper">
+<div id="claim_wrapper">
     <form name="fclaim" id="fclaim" action="{{ url_for('site_claim', cname=site.cname) }}" method="post">
         <h1>Claim this site</h1>
         <table class="">
-            <tr>
+            <tr id="row_password">
                 <th>Site password:</th>
-                <td><input type="password" name="password" id="password" value="{{ password }}" /></td>
+                <td><input type="password" name="password" id="password" value="" /></td>
             </tr>
-            <tr>
+            <tr id="row_email">
                 <th>Email address:</th>
                 <td><input type="email" name="email" id="email" value="" /></td>
             </tr>
         <p><input type="submit" id="sclaim" name="sclaim" value="Claim site"> or <a href="" />Cancel</a></p>
     </form>
 </div>                             
+{% endblock %}
+
+{% block footer %}
+<script type="text/javascript" charset="utf-8">
+    new Claim();
+</script>
 {% endblock %}