Class: Cinch::Plugins::UserLogin

Inherits:
Object
  • Object
show all
Includes:
Extensions::Authentication, Cinch::Plugin
Defined in:
lib/cinch/plugins/user_login.rb

Instance Method Summary collapse

Methods included from Extensions::Authentication

#authenticated?, #channel_status_strategy, #current_user, included, #list_strategy, #login_strategy

Instance Method Details

#login(m, nickname, password) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/cinch/plugins/user_login.rb', line 44

def (m, nickname, password)
  fetch_user = config[:fetch_user] || bot.config.authentication.fetch_user

  if fetch_user.nil?
    raise StandardError, 'You have not configured an fetch_user lambda.'
  end

  user = fetch_user.call(nickname || m.user.nick)

  if user.nil?
    m.user.notice 'You have not registered or mistyped your nickname.'
    return
  end

  unless user.respond_to? :authenticate
    raise StandardError, "Please implement #{user.class}#authenticate."
  end

  if user.authenticate(password)
    bot.config.authentication.logged_in[m.user] = user
    m.user.notice "You have been logged in as #{nickname || m.user.nick}."
  else
    m.user.notice 'Unknown username/password combination.'
  end
rescue => e
  m.user.notice 'Something went wrong.'
  raise
end

#logout(m) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/cinch/plugins/user_login.rb', line 73

def logout(m)
  if bot.config.authentication.logged_in.delete m.user
    m.user.notice 'You have been logged out.'
  else
    m.user.notice 'You are not logged in.'
  end
end

#register(m, nickname, password) ⇒ Object

Admin-only commands. Perhaps in a later version. match /add_to_(S+) (S+)/s => :method => :add_to match /remove_from_(S+) (S+)/s, :method => :remove_from



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/cinch/plugins/user_login.rb', line 26

def register(m, nickname, password)
  registration = config[:registration] || 
    bot.config.authentication.registration

  if registration.nil?
    raise StandardError, 'You have not configured a registration lambda.'
  elsif registration.call(nickname || m.user.nick, password)
    m.user.notice "You have been registered as #{nickname||m.user.nick}."
     m, nickname, password
  else
    m.user.notice "An account with nickname #{nickname || m.user.nick} " +
      'already exists.'
  end
rescue => e
  m.user.notice 'Something went wrong.'
  raise
end