Skip to content

Commit

Permalink
Also support telegram users without username.
Browse files Browse the repository at this point in the history
  • Loading branch information
martini committed Feb 15, 2017
1 parent cd28e90 commit f317cf1
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/telegram.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,19 @@ def to_user(params)
auth = Authorization.find_by(uid: message_user[:id], provider: 'telegram')

# create or update user
login = message_user[:username] || message_user[:id]
user_data = {
login: message_user[:username],
login: login,
firstname: message_user[:first_name],
lastname: message_user[:last_name],
}
if auth
user = User.find(auth.user_id)
user.update_attributes(user_data)
else
user_data[:note] = "Telegram @#{message_user[:username]}"
if message_user[:username]
user_data[:note] = "Telegram @#{message_user[:username]}"
end
user_data[:active] = true
user_data[:role_ids] = Role.signup_role_ids
user = User.create(user_data)
Expand All @@ -241,7 +244,7 @@ def to_user(params)
# create or update authorization
auth_data = {
uid: message_user[:id],
username: message_user[:username],
username: login,
user_id: user.id,
provider: 'telegram'
}
Expand Down

0 comments on commit f317cf1

Please sign in to comment.