111 lines
3.0 KiB
Ruby
111 lines
3.0 KiB
Ruby
class PseudoMembersController < PseudoSessionController
|
|
before_filter :set_key_for_this
|
|
|
|
def index
|
|
{}
|
|
end
|
|
|
|
def index_values
|
|
module_settings = PseudoMemberSetting.first
|
|
dashpath = module_settings.member_dashboard_path
|
|
dashpath = "/" + dashpath if !dashpath.starts_with?("/")
|
|
dashpath = "/" + I18n.locale.to_s + dashpath
|
|
session = OrbitHelper.request.session
|
|
current_pseudo_user = PseudoUser.find(session[:current_pseudo_user_id]) rescue nil
|
|
dashpath = dashpath + "?account=#{current_pseudo_user.user_name}" if !current_pseudo_user.nil?
|
|
{
|
|
"session_available" => !current_pseudo_user.nil?,
|
|
"dashboard_url" => dashpath
|
|
}
|
|
end
|
|
|
|
def success
|
|
{}
|
|
end
|
|
|
|
def confirm_email
|
|
params = OrbitHelper.params
|
|
page_url = "/" + I18n.locale.to_s + Page.where(:module => "pseudo_member").first.url
|
|
status = PseudoUser.confirm_email(params[:confirmation_token])
|
|
if status[:success] == true
|
|
puser = PseudoUser.find(status[:id])
|
|
puser.enabled = true
|
|
puser.save
|
|
end
|
|
{
|
|
"status" => status,
|
|
"login_url" => page_url
|
|
}
|
|
end
|
|
|
|
def register
|
|
params = OrbitHelper.params
|
|
|
|
if params[:status] == "fail"
|
|
status = "fail"
|
|
request = OrbitHelper.request
|
|
session = request.session
|
|
errors = session[:user_creation_fail]
|
|
else
|
|
status = "first"
|
|
errors = []
|
|
end
|
|
temp = {
|
|
"puser" => PseudoUser.new,
|
|
"status" => status,
|
|
"errors" => errors
|
|
}
|
|
end
|
|
|
|
# def login
|
|
# if !current_pseudo_user.nil?
|
|
# redirect_to member_dash_path(current_pseudo_user.account)
|
|
# end
|
|
# end
|
|
|
|
def register_user
|
|
puser = PseudoUser.new(pseudo_member_params)
|
|
page_url = "/" + I18n.locale.to_s + Page.where(:module => "pseudo_member").first.url
|
|
if puser.save
|
|
puser.generate_confirmation_token("http://#{request.host_with_port}#{page_url}?method=confirm_email")
|
|
redirect_to page_url + "?method=success"
|
|
else
|
|
session[:user_creation_fail] = puser.errors.full_messages
|
|
redirect_to page_url + "?method=register&status=fail"
|
|
end
|
|
end
|
|
|
|
def logoutuser
|
|
destroy_pseudo_session
|
|
loginpath = "/" + I18n.locale.to_s + Page.where(:module => "pseudo_member").first.url
|
|
redirect_to loginpath
|
|
end
|
|
|
|
def loginuser
|
|
user = PseudoUser.where(:user_name => params[:username]).first rescue nil
|
|
loginpath = "/" + I18n.locale.to_s + Page.where(:module => "pseudo_member").first.url
|
|
dashpath = @module_settings.member_dashboard_path
|
|
dashpath = "/" + dashpath if !dashpath.starts_with?("/")
|
|
dashpath = "/" + I18n.locale.to_s + dashpath
|
|
if user.nil?
|
|
redirect_to loginpath + "?error=invld"
|
|
else
|
|
if user.enabled
|
|
if user.authenticate(params[:password])
|
|
create_pseudo_session(user)
|
|
redirect_to dashpath + "?account=#{user.user_name}"
|
|
else
|
|
redirect_to loginpath + "?error=invld"
|
|
end
|
|
else
|
|
redirect_to loginpath + "?error=dsbld"
|
|
end
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def pseudo_member_params
|
|
params.require(:pseudo_user).permit!
|
|
end
|
|
end |