Module: Omnigollum::Helpers

Defined in:
lib/omnigollum.rb

Instance Method Summary collapse

Instance Method Details

#auth_configObject


66
67
68
69
70
71
72
73
74
75
76
# File 'lib/omnigollum.rb', line 66

def auth_config
  options = settings.send(:omnigollum)

  @auth = {
    :route_prefix => options[:route_prefix],
    :providers    => options[:provider_names],
    :path_images  => options[:path_images],
    :logo_suffix  => options[:logo_suffix],
    :logo_missing => options[:logo_missing]
  }
end

#commit_messageObject


107
108
109
110
111
112
113
114
# File 'lib/omnigollum.rb', line 107

def commit_message
  if user_authed?
    user = get_user
    return { :message => params[:message], :name => user.name, :email => user.email}
  else
    return { :message => params[:message]}
  end
end

#get_userObject


58
59
60
# File 'lib/omnigollum.rb', line 58

def get_user
  session[:omniauth_user]
end

#kick_backObject


51
52
53
54
55
56
# File 'lib/omnigollum.rb', line 51

def kick_back
  redirect !request.referrer.nil? && request.referrer !~ /#{Regexp.escape(settings.send(:omnigollum)[:route_prefix])}\/.*/ ?
    request.referrer:
    '/'
  halt
end

#show_errorObject


100
101
102
103
104
105
# File 'lib/omnigollum.rb', line 100

def show_error
  options = settings.send(:omnigollum)
  auth_config
  require options[:path_views] + '/error'
  halt mustache Omnigollum::Views::Error
end

#show_loginObject


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/omnigollum.rb', line 78

def 
  options = settings.send(:omnigollum)

  # Don't bother showing the login screen, just redirect
  if options[:provider_names].count == 1
    if !request.params['origin'].nil?
      origin = request.params['origin']
    elsif !request.path.nil?
      origin = request.path
    else
      origin = '/'
    end

    redirect (request.script_name || '') + options[:route_prefix] + '/auth/' + options[:provider_names].first.to_s + "?origin=" +
       CGI.escape(origin)
  else
     auth_config
     require options[:path_views] + '/login'
     halt mustache Omnigollum::Views::Login
  end
end

#user_authObject


45
46
47
48
49
# File 'lib/omnigollum.rb', line 45

def user_auth
  @title   = 'Authentication is required'
  @subtext = 'Please choose a login service'
  
end

#user_authed?Boolean

Returns:

  • (Boolean)

41
42
43
# File 'lib/omnigollum.rb', line 41

def user_authed?
  session.has_key? :omniauth_user
end

#user_deauthObject


62
63
64
# File 'lib/omnigollum.rb', line 62

def user_deauth
  session.delete :omniauth_user
end