summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2011-01-28 17:38:58 +0100
committerChristoph Helma <helma@in-silico.ch>2011-01-28 17:38:58 +0100
commit4edc55affca2a5312f5e9b03c874c02c0fc0dce6 (patch)
tree888430231f2ce8839b52d5ec66f335ee41859401
parente4f86ba5f38e03aa6ee257be75d63dc54e07ab10 (diff)
default login as guest
-rw-r--r--application.rb21
-rw-r--r--helper.rb1
-rw-r--r--views/create.haml18
-rw-r--r--views/layout.haml4
-rw-r--r--views/login.haml53
-rw-r--r--views/style.sass52
6 files changed, 93 insertions, 56 deletions
diff --git a/application.rb b/application.rb
index 2790076..fe5f511 100644
--- a/application.rb
+++ b/application.rb
@@ -29,12 +29,13 @@ helpers do
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
@@ -352,20 +353,24 @@ post "/lazar/?" do # get detailed prediction
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
diff --git a/helper.rb b/helper.rb
index e892669..3fbd06f 100644
--- a/helper.rb
+++ b/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
diff --git a/views/create.haml b/views/create.haml
index 5aeac67..c04f841 100644
--- a/views/create.haml
+++ b/views/create.haml
@@ -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'
@@ -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.
diff --git a/views/layout.haml b/views/layout.haml
index f1b63e9..78af858 100644
--- a/views/layout.haml
+++ b/views/layout.haml
@@ -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
diff --git a/views/login.haml b/views/login.haml
index 747430e..6d15bb7 100644
--- a/views/login.haml
+++ b/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'
diff --git a/views/style.sass b/views/style.sass
index 5f362a3..b69e28c 100644
--- a/views/style.sass
+++ b/views/style.sass
@@ -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
@@ -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
@@ -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
@@ -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