Use settings params to check if password reset and new user creation is enbled.

This commit is contained in:
Martin Edenhofer 2013-01-08 01:43:07 +01:00
parent ee77792db4
commit c34240c74d
5 changed files with 37 additions and 7 deletions

View file

@ -11,6 +11,11 @@ class Index extends App.Controller
constructor: -> constructor: ->
super super
# go back if feature is not enabled
if !@Config.get('user_lost_password')
@navigate '#'
return
# set title # set title
@title 'Reset Password' @title 'Reset Password'
@navupdate '#reset_password' @navupdate '#reset_password'

View file

@ -11,6 +11,11 @@ class Index extends App.Controller
constructor: -> constructor: ->
super super
# go back if feature is not enabled
if !@Config.get('user_create_account')
@navigate '#'
return
# set title # set title
@title 'Sign up' @title 'Sign up'
@navupdate '#signup' @navupdate '#signup'

View file

@ -13,8 +13,10 @@
<button class="btn btn-primary" type="submit"><%- @T( 'Sign in' ) %></button> <button class="btn btn-primary" type="submit"><%- @T( 'Sign in' ) %></button>
<div> <div>
<span class="small"><input name="remember_me" value="1" type="checkbox"/> <%- @T( 'Remember me' ) %></span> <span class="small"><input name="remember_me" value="1" type="checkbox"/> <%- @T( 'Remember me' ) %></span>
<% if @C('user_lost_password'): %>
<span class="small">&middot;</span> <span class="small">&middot;</span>
<a href="#reset_password" class="small"><%- @T( 'Forgot password?' ) %></a> <a href="#reset_password" class="small"><%- @T( 'Forgot password?' ) %></a>
<% end %>
</div> </div>
</form> </form>
</div> </div>
@ -39,6 +41,7 @@
</div> </div>
<% end %> <% end %>
<% if @C('user_create_account'): %>
<div class="row"> <div class="row">
<div class="span12"> <div class="span12">
<p>--- <%- @T( 'or' ) %> ---</p> <p>--- <%- @T( 'or' ) %> ---</p>
@ -47,10 +50,11 @@
<div class="row"> <div class="row">
<div class="span12"> <div class="span12">
<p><%- @T( 'New to' ) %> <%= @C( 'product_name' ) %>, <%- @T( 'join today!' ) %></p> <p><%- @T( 'New to %s join today!', @C( 'product_name' ) ) %></p>
<p><a href="#signup" class="btn"><%- @T( 'Sign up' ) %></a> <p><a href="#signup" class="btn"><%- @T( 'Sign up' ) %></a>
</div> </div>
</div> </div>
<% end %>
</div> </div>

View file

@ -21,6 +21,14 @@ class SessionsController < ApplicationController
# auto population of default collections # auto population of default collections
default_collection = SessionHelper::default_collections(user) default_collection = SessionHelper::default_collections(user)
# remember me - set session cookie to expire later
reset_session
if params[:remember_me]
request.env['rack.session.options'][:expire_after] = 1.year.from_now
else
request.env['rack.session.options'][:expire_after] = nil
end
# set session user_id # set session user_id
user = User.find_fulldata(user.id) user = User.find_fulldata(user.id)
session[:user_id] = user['id'] session[:user_id] = user['id']
@ -37,11 +45,6 @@ class SessionsController < ApplicationController
) )
end end
# remember me - set session cookie to expire later
if params[:remember_me]
request.env['rack.session.options'][:expire_after] = 1.year.from_now
end
# return new session data # return new session data
render :json => { render :json => {
:session => user, :session => user,

View file

@ -124,6 +124,12 @@ curl http://localhost/api/users.json -v -u #{login}:#{password} -H "Content-Type
# if it's a signup, add user to customer role # if it's a signup, add user to customer role
if user.created_by_id == 1 if user.created_by_id == 1
# check if feature is enabled
if !Setting.get('user_create_account')
render :json => { :error => 'Feature not enabled!' }, :status => :unprocessable_entity
return
end
# check if it's first user # check if it's first user
count = User.all.count() count = User.all.count()
group_ids = [] group_ids = []
@ -311,6 +317,13 @@ curl http://localhost/api/users/password_reset.json -v -u #{login}:#{password} -
=end =end
def password_reset_send def password_reset_send
# check if feature is enabled
if !Setting.get('user_lost_password')
render :json => { :error => 'Feature not enabled!' }, :status => :unprocessable_entity
return
end
success = User.password_reset_send( params[:username] ) success = User.password_reset_send( params[:username] )
if success if success
render :json => { :message => 'ok' }, :status => :ok render :json => { :message => 'ok' }, :status => :ok