Skip to content

Commit

Permalink
Merge remote branch 'helma/development' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
rautenberg committed Jan 31, 2011
2 parents a64ce9f + 4edc55a commit 57ac583
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 56 deletions.
21 changes: 13 additions & 8 deletions application.rb
Expand Up @@ -48,12 +48,13 @@ def delete_dependent(uri, subjectid=nil)
end

before do
unless env['REQUEST_METHOD'] == "GET" or ( env['REQUEST_URI'] =~ /\/login$/ and env['REQUEST_METHOD'] == "POST" ) or !AA_SERVER
if !logged_in()
flash[:notice] = "You have to login first to do this."
redirect url_for('/login')
#unless env['REQUEST_METHOD'] == "GET" or ( env['REQUEST_URI'] =~ /\/login$/ and env['REQUEST_METHOD'] == "POST" ) or !AA_SERVER
if !logged_in and !( env['REQUEST_URI'] =~ /\/login$/ and env['REQUEST_METHOD'] == "POST" ) #or !AA_SERVER
login("guest","guest")
#flash[:notice] = "You have to login first to do this."
#redirect url_for('/login')
end
end
#end
end

get '/?' do
Expand Down Expand Up @@ -404,20 +405,24 @@ def delete_dependent(uri, subjectid=nil)
end

post '/login' do
=begin
if session[:subjectid] != nil
flash[:notice] = "You are already logged in as user: #{session[:username]}. Please log out first."
redirect url_for('/login')
end
=end
if params[:username] == '' || params[:password] == ''
flash[:notice] = "Please enter username and password."
redirect url_for('/login')
end
if login(params[:username], params[:password])
flash[:notice] = "Login successful."
flash[:notice] = "Welcome #{session[:username]}!"
redirect url_for('/create')
#haml :create
else
flash[:notice] = "Login failed."
flash[:notice] = "Login failed. Please try again."
haml :login
end
haml :login
end

post '/logout' do
Expand Down
1 change: 1 addition & 0 deletions helper.rb
@@ -1,6 +1,7 @@
helpers do

def login(username, password)
logout
session[:subjectid] = OpenTox::Authorization.authenticate(username, password)
LOGGER.debug "ToxCreate login user #{username} with subjectid: " + session[:subjectid].to_s
if session[:subjectid] != nil
Expand Down
18 changes: 13 additions & 5 deletions views/create.haml
Expand Up @@ -19,18 +19,15 @@
before submitting.

%form{ :action => url_for('/models'), :method => "post", :enctype => "multipart/form-data" }
%input{:type => 'hidden', :name => 'subjectid', :id => 'subjectid', :value => session[:subjectid]}
%fieldset
-#%label{:for => 'endpoint'} 1. Enter #{toggle_link("#endpoint_description","endpoint")} name and #{toggle_link("#unit","unit")} (for #{toggle_link("#regression","regression")}):
-#%input{:type => 'text', :name => 'endpoint', :id => 'endpoint', :size => '50'}
-#%br
%label{:for => 'file'}
Select training dataset in
Select training data in
= link_to "Excel", '/help'
or
= link_to "CSV", '/help'
format:
%input{:type => 'file', :name => 'file', :id => 'file', :size => '41'}
%input{:type => 'hidden', :name => 'subjectid', :id => 'subjectid', :value => session[:subjectid]}
%input{ :type => "submit", :value => "Create model"}
= link_to "Cancel", '/create'

Expand All @@ -40,3 +37,14 @@
= haml :regression, :layout => false
= haml :endpoint, :layout => false
= haml :unit, :layout => false

.login_notice

- if session[:username] == "guest"
You are currently logged in as
%b guest
and your models can be modified or deleted by other guests. Please
= link_to "log in", "/login"
with your
%a{:href => "www.opentox.org"} OpenTox
account to control your model permissions.
4 changes: 4 additions & 0 deletions views/layout.haml
Expand Up @@ -28,6 +28,10 @@
= link_to "Help", "/help"

.content
.login_info
User:
%b= session[:username]

- if `hostname`.match(/ot-test/)
.notice
This service is for testing purposes only - once a week all models will be deleted. Please send bug reports and feature requests to our
Expand Down
53 changes: 34 additions & 19 deletions views/login.haml
@@ -1,32 +1,47 @@
.input

%p
Please login as guest or user. You can create a user account at
= link_to "www.opentox.org/join_form .", "http://www.opentox.org/join_form"
- if !logged_in()
%form{ :action => url_for('/login'), :method => "post" }
%fieldset
%label{:for => 'username'} Username:
%input{:type => 'text', :name => 'username', :id => 'username', :size => '50'}
%br
%label{:for => 'password'} Password:
%input{:type => 'password', :name => 'password', :id => 'password', :size => '50'}
%input{ :type => "submit", :value => "Login"}
= link_to "Cancel", '/login'
- if session[:username] == "guest"
.login_notice
You are currently logged in as
%b guest
and your models can be modified or deleted by other guests.
To control models permissions you can
log in with your
%a{:href => "http://www.opentox.org"} OpenTox
username/password below. If have no
%a{:href => "http://www.opentox.org"} OpenTox
account yet you can
%a{:href => "http://www.opentox.org/join_form"} register here.
- else
%p
Change
%a{:href => "http://www.opentox.org"} OpenTox
account:

-# if !logged_in()
%form{ :action => url_for('/login'), :method => "post" }
%fieldset
%label{:for => 'username'} Username:
%input{:type => 'text', :name => 'username', :id => 'username', :size => '50'}
%br
%label{:for => 'password'} Password:
%input{:type => 'password', :name => 'password', :id => 'password', :size => '50'}
%input{ :type => "submit", :value => "Login"}
= link_to "Cancel", '/login'
- if session[:username] != "guest"
%br
or login with guest-account:
%form{ :action => url_for('/login'), :method => "post" }
%input{:type => 'hidden', :name => 'username', :id => 'username', :value => "guest"}
%input{:type => 'hidden', :name => 'password', :id => 'password', :value => "guest"}
%input{ :type => "submit", :value => "Login as guest"}
- else
-# else
%form{ :action => url_for('/logout'), :method => "post" }
%p
You are logged in as user:
-#%p
You are logged in as:
%b= session[:username]
- if LOGGER.level == Logger::DEBUG
-# if LOGGER.level == Logger::DEBUG
%br
= session[:subjectid]
%input{ :type => "submit", :value => "Logout"}
%input{ :type => "submit", :value => "Switch user"}
= link_to "Cancel", '/login'

52 changes: 28 additions & 24 deletions views/style.sass
Expand Up @@ -4,7 +4,7 @@ $fg_color: #424345
$ot_purple: #5d308a
$body_color: white
$text_color: black
$notice_border: black
$notice_border: red

body
min-width: 30em
Expand Down Expand Up @@ -34,13 +34,10 @@ body
margin: 0
padding: 2px
display: inline
border-right: 1px solid
color: $body_color
border-top: 1px solid
color: $body_color
border-right: 1px solid $body_color
border-bottom: 1px solid $body_color
background-color: $fg_color
padding-left: 0.5em
padding-right: 0.5em
padding: 0.2em 0.5em
font-weight: bold
a
text-decoration: none
Expand All @@ -50,48 +47,55 @@ body
li.selected
font-weight: bold
background-color: $bg_color
border: 1px solid
color: $fg_color
border-bottom: 1px solid
color: $bg_color
border-bottom: 1px solid $bg_color
a
color: $text_color

.content
clear: both
background-color: $bg_color
height: 100%
padding: 1em
border: 1px solid
color: $fg_color
border-top: 1px solid $body_color
h2
margin: 20px 3px 2px 3px
.notice
padding: 1em
//clear: both
//margin-top: 1em
padding: 0.5em 1em
background-color: $body_color
border: 1px solid
border-color: $notice_border
.login_info
text-align: right
font-size: small
.login_notice
//clear: both
font-size: small
background-color: $bg_color
padding: 1em 0em
//font-style: italic
.input
//clear: both
text-align: left
form
padding: 1em
background-color: $bg_color2
border: 1px solid
color: $fg_color
fieldset
margin: 0
//margin: 0
padding: 0
padding-right: 1em
border: 0
legend
font-weight: bold
color: $fg_color
label
width: 28em
display: block
float: left
//width: 28em
//display: block
//float: left
br
clear: both
//clear: both
.code
border: 1px solid black
padding: 1%
background-color: white
table
Expand Down Expand Up @@ -182,9 +186,9 @@ body
//overflow-y: scroll;
.model
padding: 0em 1em
padding: 0.5em 1em
background-color: $bg_color2
border: 1px solid
border: 0
margin-top: 0.6em
dl
dt
Expand Down

0 comments on commit 57ac583

Please sign in to comment.