# Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
+ def authorize_web
+ @user = User.find_by_token(session[:token])
+ end
-
- # HTTP AUTH stuff for the API
-
def authorize(realm='Web Password', errormessage="Could't authenticate you")
username, passwd = get_auth_data
# check if authorized
class SiteController < ApplicationController
+ before_filter :authorize_web
+
def index
end
end
def new
+ render :layout => 'site'
+ end
+
+ def login
+ if params[:user]
+ email = params[:user][:email]
+ pass = params[:user][:password]
+ u = User.authenticate(email, pass)
+ if u
+ u.token = User.make_token
+ u.timeout = 1.day.from_now
+ u.save
+ session[:token] = u.token
+ redirect_to :controller => 'site', :action => 'index'
+ return
+ end
+ end
+
+ render :layout => 'site'
+ end
+ def logout
+ if session[:token]
+ u = User.find_by_token(session[:token])
+ if u
+ u.token = User.make_token
+ u.timeout = Time.now
+ u.save
+ end
+ end
+ session[:token] = nil
+ redirect_to :controller => 'site', :action => 'index'
end
def confirm
@user.active = true
@user.save
flash[:notice] = 'Confirmed your account'
+
+ #FIXME: login the person magically
+
redirect_to :action => 'login'
else
flash[:notice] = 'Something went wrong confirming that user'
def set_defaults
self.creation_time = Time.now
self.timeout = Time.now
- self.token = make_token()
+ self.token = User.make_token()
end
def pass_crypt=(str)
def self.authenticate(email, passwd)
find_first([ "email = ? AND pass_crypt =?", email, Digest::MD5.hexdigest(passwd) ])
end
+
+ def self.authenticate_token(token)
+ find_first([ "token = ? ", token])
+ end
- private
- def make_token
+ def self.make_token
chars = 'abcdefghijklmnopqrtuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
confirmstring = ''
</div>
<span id="greeting">
- <%= link_to 'Login', {:controller => 'user', :action => 'login'}, {:id => 'loginanchor'}%> /
- <%= link_to 'Sign up', {:controller => 'user', :action => 'new'}, {:id => 'registeranchor'} %>
+ <% if @user %>
+ Welcome, <%= @user.email %> /
+ <%= link_to 'Logout', {:controller => 'user', :action => 'logout'}, {:id => 'loginanchor'}%>
+ <% else %>
+ <%= link_to 'Login', {:controller => 'user', :action => 'login'}, {:id => 'loginanchor'}%> /
+ <%= link_to 'Sign up', {:controller => 'user', :action => 'new'}, {:id => 'registeranchor'} %>
+ <% end %>
</span>
<div>
<ul id="tabnav">
- <li><a id="viewanchor" href="/index.html" title="view maps">View</a></li>
- <li><a style="font-style:italic" href="/login.html" title="edit maps">Edit</a></li>
- <li><a href="/traces" title="manage traces">GPS traces</a></li>
+ <!-- FIXME, these links need help -->
+ <% if @user %>
+ <li><%= link_to 'View', {:controller => 'site', :action => 'index'}, {:id => 'viewanchor', :title => 'view maps' } %></li>
+ <li><%= link_to 'Edit', {:controller => 'site', :action => 'edit'}, {:id => 'editanchor', :title => 'edit maps' } %></li>
+ <li><%= link_to 'GPS traces', {:controller => 'trace', :action => 'index'}, {:id => 'traceanchor', :title => 'manage traces' } %></li>
+ <% else %>
+ <li><a id="viewanchor" href="/index.html" title="view maps">View</a></li>
+ <li><a style="font-style:italic" href="/login.html" title="edit maps">Edit</a></li>
+ <li><a href="/traces" title="manage traces">GPS traces</a></li>
+ <% end %>
</ul>
</div>
</div>
-
<div id="cclogo">
<center>
+
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but21.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
- <input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----MIIHFgYJKoZIhvcNAQcEoIIHBzCCBwMCAQExggEwMIIBLAIBADCBlDCBjjELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtQYXlQYWwgSW5jLjETMBEGA1UECxQKbGl2ZV9jZXJ0czERMA8GA1UEAxQIbGl2ZV9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb20CAQAwDQYJKoZIhvcNAQEBBQAEgYBJr8BolWgGYvrtd1+IKusKyffII5UlFikz+JVREV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VfY2VydHMxETAPBgNVBAMUCGxpdmVfYXBpMRwwGgYJKoZIhvcNAQkBFg1yZUBwYXlwYWwuY29tAgEAMAkGBSsOAwIaBQCgXTAYBgkqhkiG9w0BCQMxCwYJKoZIhvcNAQcBMBwGCSqGSIb3DQEJBTEPFw0wNjA4MjYwODQ2NDdaMCMGCSqGSIb3DQEJBDEWBBTyC1ZchvuTMtcYeudPPSP/w8HiEDANBgkqhkiG9w0BAQEFAASBgJPpBf69pRAJfhzv/MfPiMncuq3TSlvpX7VtG9p4dXzSko4i2lWUDD72r5zdF2NwDgZ6avf630PutgpOzYJQ525If1xU2olc9DWI43UZTqY+FArgFuCJ8VnkPsy9mcbXPoSjLRqNwrsA2yoETxMISO3ASELzELJTJgpPk4bU57eZ-----END PKCS7-----">
</form>
<a href="http://creativecommons.org/licenses/by-sa/2.0/"><img src="/images/cc_button.png" border="0"></a>
</div>
</div>
- </body>
-</html>
+ </body>
+ </html>
<div id="debuginfo"></div>
+<% unless @user %>
+<div id="gads">
+ <script type="text/javascript"><!--
+ google_ad_client = "pub-7727744269903103";
+ google_ad_width = 728;
+ google_ad_height = 90;
+ google_ad_format = "728x90_as";
+ google_ad_type = "text";
+ google_ad_channel ="";
+ google_color_border = "CCCCCC";
+ google_color_bg = "FFFFFF";
+ google_color_link = "000000";
+ google_color_url = "000080";
+ google_color_text = "000000";
+ //--></script><script type="text/javascript"
+ src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
+ </script>We're trialing adverts to support the project. Login and they go away.
+</div>
+<% end %>
+
+
<script type="text/javascript">
lat = 0;
lon = 0;
<h1>Login:</h1><br>
Please login or <%= link_to 'create an account', :controller => 'user', :action => 'new' %>.<br>
-
<%= start_form_tag :action => 'login' %>
<table>
- <tr><td>Login name</td><td><%= text_field('user', 'display_name',{:size => 50, :maxlength => 255}) %></td></tr>
+ <tr><td>Login name</td><td><%= text_field('user', 'email',{:size => 50, :maxlength => 255}) %></td></tr>
<tr><td>password:</td><td><%= password_field('user', 'password',{:size => 50, :maxlength => 255}) %></td></tr>
</table>
map.connect 'api/0.4/segment/:id', :controller => 'segment', :action => 'rest'
map.connect '/', :controller => 'site', :action => 'index'
+ map.connect '/index.html', :controller => 'site', :action => 'index'
+ map.connect '/edit.html', :controller => 'site', :action => 'edit'
+ map.connect '/login.html', :controller => 'user', :action => 'login'
+ map.connect '/logout.html', :controller => 'user', :action => 'logout'
+ map.connect '/create-account.html', :controller => 'user', :action => 'new'
map.connect ':controller/:action/:id'
end