{"action":"created","comment":{"url":"https://api.github.com/repos/webmstk/qaa/pulls/comments/42480136","id":42480136,"diff_hunk":"@@ -0,0 +1,64 @@\n+class Users::SessionsController < Devise::SessionsController\n+  before_action :load_authorization\n+\n+  def email\n+    render :thank_you if @authorization.nil?\n+  end\n+\n+\n+  def send_email\n+    if params[:email].blank?\n+      redirect_to \"/users/email?authorization=#{@authorization.id}\"\n+      flash[:notice] = 'Укажите правильный email'\n+    else\n+      link = get_auth_link(@authorization, params[:email])\n+      UserMailer.verify_email(params[:email], link).deliver_now\n+      redirect_to '/users/email'\n+    end\n+  end\n+\n+\n+  def authorizate\n+    if @authorization.confirmed\n+      render :confirmed\n+    elsif get_auth_hash(@authorization, params[:email]) == params[:code]\n+      authorize_user_by_auth_hash(@authorization, params[:email])\n+    end\n+  end\n+\n+\n+  private\n+\n+    def load_authorization\n+      @authorization = Authorization.where(id: params[:authorization]).first\n+    end\n+\n+\n+    def get_auth_link(authorization, email)\n+      verification_code = get_auth_hash(authorization, params[:email])\n+\n+      return \"http://qaa.dev/users/authorizate/?authorization=#{authorization.id}&email=#{params[:email]}&code=#{verification_code}\"\n+    end\n+\n+\n+    def get_auth_hash(authorization, email)\n+      return Digest::MD5.hexdigest(authorization.provider + authorization.uid + email)\n+    end\n+\n+\n+    def authorize_user_by_auth_hash(authorization, email)\n+      password = Devise.friendly_token[0, 20]\n+      user = User.where(email: params[:email]).first\n+      unless(user)\n+        user = User.create!(email: params[:email], password: password, password_confirmation: password)\n+      end\n+\n+      authorization.user = user","path":"app/controllers/users/sessions_controller.rb","position":56,"original_position":56,"commit_id":"cef552a482596729904674e204be21d0d68888f3","original_commit_id":"cef552a482596729904674e204be21d0d68888f3","user":{"login":"vkurennov","id":968537,"avatar_url":"https://avatars.githubusercontent.com/u/968537?v=3","gravatar_id":"","url":"https://api.github.com/users/vkurennov","html_url":"https://github.com/vkurennov","followers_url":"https://api.github.com/users/vkurennov/followers","following_url":"https://api.github.com/users/vkurennov/following{/other_user}","gists_url":"https://api.github.com/users/vkurennov/gists{/gist_id}","starred_url":"https://api.github.com/users/vkurennov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vkurennov/subscriptions","organizations_url":"https://api.github.com/users/vkurennov/orgs","repos_url":"https://api.github.com/users/vkurennov/repos","events_url":"https://api.github.com/users/vkurennov/events{/privacy}","received_events_url":"https://api.github.com/users/vkurennov/received_events","type":"User","site_admin":false},"body":"Эти 3 строки можно заменить на 1 с update","created_at":"2015-10-20T10:45:44Z","updated_at":"2015-10-20T10:45:44Z","html_url":"https://github.com/webmstk/qaa/pull/10#discussion_r42480136","pull_request_url":"https://api.github.com/repos/webmstk/qaa/pulls/10","_links":{"self":{"href":"https://api.github.com/repos/webmstk/qaa/pulls/comments/42480136"},"html":{"href":"https://github.com/webmstk/qaa/pull/10#discussion_r42480136"},"pull_request":{"href":"https://api.github.com/repos/webmstk/qaa/pulls/10"}}},"pull_request":{"url":"https://api.github.com/repos/webmstk/qaa/pulls/10","id":48051674,"html_url":"https://github.com/webmstk/qaa/pull/10","diff_url":"https://github.com/webmstk/qaa/pull/10.diff","patch_url":"https://github.com/webmstk/qaa/pull/10.patch","issue_url":"https://api.github.com/repos/webmstk/qaa/issues/10","number":10,"state":"open","locked":false,"title":"do lesson 12","user":{"login":"webmstk","id":10058472,"avatar_url":"https://avatars.githubusercontent.com/u/10058472?v=3","gravatar_id":"","url":"https://api.github.com/users/webmstk","html_url":"https://github.com/webmstk","followers_url":"https://api.github.com/users/webmstk/followers","following_url":"https://api.github.com/users/webmstk/following{/other_user}","gists_url":"https://api.github.com/users/webmstk/gists{/gist_id}","starred_url":"https://api.github.com/users/webmstk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/webmstk/subscriptions","organizations_url":"https://api.github.com/users/webmstk/orgs","repos_url":"https://api.github.com/users/webmstk/repos","events_url":"https://api.github.com/users/webmstk/events{/privacy}","received_events_url":"https://api.github.com/users/webmstk/received_events","type":"User","site_admin":false},"body":"Реализована аутентификация через Facebook, Вконтакте и Twitter.\r\n\r\nВ случае с твиттером решил поступить так - авторизация создаётся, но она не привязана к пользователю и имеет поле confirmed=false. Как только пользователь подтверждает почту, авторизация привязывается к тут же создаваемому пользователю и меняет confirmed на true. В принципе, поле confirmed необязательно, но что сделано, то сделано.\r\n\r\nКое-что осталось непонятным - почему при аутентификации в контроллере строка\r\n\r\n    set_flash_message(:notice, :success, kind: 'Twitter') if is_navigational_format?\r\n\r\nвызывает\r\n\r\n    translation missing: ru.devise.sessions.user.success\r\n\r\nхотя тот же метод, написанный в user.rb показывает правильный перевод. Хотелось бы это понять.\r\n\r\nИ ещё - в какой константе хранится адрес сайта? )","created_at":"2015-10-19T10:00:41Z","updated_at":"2015-10-20T10:45:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9ebd6ccdf4a486adf61ad2eb5de762c69e12b3fe","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/webmstk/qaa/pulls/10/commits","review_comments_url":"https://api.github.com/repos/webmstk/qaa/pulls/10/comments","review_comment_url":"https://api.github.com/repos/webmstk/qaa/pulls/comments{/number}","comments_url":"https://api.github.com/repos/webmstk/qaa/issues/10/comments","statuses_url":"https://api.github.com/repos/webmstk/qaa/statuses/cef552a482596729904674e204be21d0d68888f3","head":{"label":"webmstk:task12","ref":"task12","sha":"cef552a482596729904674e204be21d0d68888f3","user":{"login":"webmstk","id":10058472,"avatar_url":"https://avatars.githubusercontent.com/u/10058472?v=3","gravatar_id":"","url":"https://api.github.com/users/webmstk","html_url":"https://github.com/webmstk","followers_url":"https://api.github.com/users/webmstk/followers","following_url":"https://api.github.com/users/webmstk/following{/other_user}","gists_url":"https://api.github.com/users/webmstk/gists{/gist_id}","starred_url":"https://api.github.com/users/webmstk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/webmstk/subscriptions","organizations_url":"https://api.github.com/users/webmstk/orgs","repos_url":"https://api.github.com/users/webmstk/repos","events_url":"https://api.github.com/users/webmstk/events{/privacy}","received_events_url":"https://api.github.com/users/webmstk/received_events","type":"User","site_admin":false},"repo":{"id":36569251,"name":"qaa","full_name":"webmstk/qaa","owner":{"login":"webmstk","id":10058472,"avatar_url":"https://avatars.githubusercontent.com/u/10058472?v=3","gravatar_id":"","url":"https://api.github.com/users/webmstk","html_url":"https://github.com/webmstk","followers_url":"https://api.github.com/users/webmstk/followers","following_url":"https://api.github.com/users/webmstk/following{/other_user}","gists_url":"https://api.github.com/users/webmstk/gists{/gist_id}","starred_url":"https://api.github.com/users/webmstk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/webmstk/subscriptions","organizations_url":"https://api.github.com/users/webmstk/orgs","repos_url":"https://api.github.com/users/webmstk/repos","events_url":"https://api.github.com/users/webmstk/events{/privacy}","received_events_url":"https://api.github.com/users/webmstk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/webmstk/qaa","description":"Questions & Answers project","fork":false,"url":"https://api.github.com/repos/webmstk/qaa","forks_url":"https://api.github.com/repos/webmstk/qaa/forks","keys_url":"https://api.github.com/repos/webmstk/qaa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/webmstk/qaa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/webmstk/qaa/teams","hooks_url":"https://api.github.com/repos/webmstk/qaa/hooks","issue_events_url":"https://api.github.com/repos/webmstk/qaa/issues/events{/number}","events_url":"https://api.github.com/repos/webmstk/qaa/events","assignees_url":"https://api.github.com/repos/webmstk/qaa/assignees{/user}","branches_url":"https://api.github.com/repos/webmstk/qaa/branches{/branch}","tags_url":"https://api.github.com/repos/webmstk/qaa/tags","blobs_url":"https://api.github.com/repos/webmstk/qaa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/webmstk/qaa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/webmstk/qaa/git/refs{/sha}","trees_url":"https://api.github.com/repos/webmstk/qaa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/webmstk/qaa/statuses/{sha}","languages_url":"https://api.github.com/repos/webmstk/qaa/languages","stargazers_url":"https://api.github.com/repos/webmstk/qaa/stargazers","contributors_url":"https://api.github.com/repos/webmstk/qaa/contributors","subscribers_url":"https://api.github.com/repos/webmstk/qaa/subscribers","subscription_url":"https://api.github.com/repos/webmstk/qaa/subscription","commits_url":"https://api.github.com/repos/webmstk/qaa/commits{/sha}","git_commits_url":"https://api.github.com/repos/webmstk/qaa/git/commits{/sha}","comments_url":"https://api.github.com/repos/webmstk/qaa/comments{/number}","issue_comment_url":"https://api.github.com/repos/webmstk/qaa/issues/comments{/number}","contents_url":"https://api.github.com/repos/webmstk/qaa/contents/{+path}","compare_url":"https://api.github.com/repos/webmstk/qaa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/webmstk/qaa/merges","archive_url":"https://api.github.com/repos/webmstk/qaa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/webmstk/qaa/downloads","issues_url":"https://api.github.com/repos/webmstk/qaa/issues{/number}","pulls_url":"https://api.github.com/repos/webmstk/qaa/pulls{/number}","milestones_url":"https://api.github.com/repos/webmstk/qaa/milestones{/number}","notifications_url":"https://api.github.com/repos/webmstk/qaa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/webmstk/qaa/labels{/name}","releases_url":"https://api.github.com/repos/webmstk/qaa/releases{/id}","created_at":"2015-05-30T18:00:10Z","updated_at":"2015-05-30T18:01:36Z","pushed_at":"2015-10-19T10:00:41Z","git_url":"git://github.com/webmstk/qaa.git","ssh_url":"git@github.com:webmstk/qaa.git","clone_url":"https://github.com/webmstk/qaa.git","svn_url":"https://github.com/webmstk/qaa","homepage":null,"size":564,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"webmstk:master","ref":"master","sha":"d3f9f4a10e9184b749730e1c602f2161a6eeef9b","user":{"login":"webmstk","id":10058472,"avatar_url":"https://avatars.githubusercontent.com/u/10058472?v=3","gravatar_id":"","url":"https://api.github.com/users/webmstk","html_url":"https://github.com/webmstk","followers_url":"https://api.github.com/users/webmstk/followers","following_url":"https://api.github.com/users/webmstk/following{/other_user}","gists_url":"https://api.github.com/users/webmstk/gists{/gist_id}","starred_url":"https://api.github.com/users/webmstk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/webmstk/subscriptions","organizations_url":"https://api.github.com/users/webmstk/orgs","repos_url":"https://api.github.com/users/webmstk/repos","events_url":"https://api.github.com/users/webmstk/events{/privacy}","received_events_url":"https://api.github.com/users/webmstk/received_events","type":"User","site_admin":false},"repo":{"id":36569251,"name":"qaa","full_name":"webmstk/qaa","owner":{"login":"webmstk","id":10058472,"avatar_url":"https://avatars.githubusercontent.com/u/10058472?v=3","gravatar_id":"","url":"https://api.github.com/users/webmstk","html_url":"https://github.com/webmstk","followers_url":"https://api.github.com/users/webmstk/followers","following_url":"https://api.github.com/users/webmstk/following{/other_user}","gists_url":"https://api.github.com/users/webmstk/gists{/gist_id}","starred_url":"https://api.github.com/users/webmstk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/webmstk/subscriptions","organizations_url":"https://api.github.com/users/webmstk/orgs","repos_url":"https://api.github.com/users/webmstk/repos","events_url":"https://api.github.com/users/webmstk/events{/privacy}","received_events_url":"https://api.github.com/users/webmstk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/webmstk/qaa","description":"Questions & Answers project","fork":false,"url":"https://api.github.com/repos/webmstk/qaa","forks_url":"https://api.github.com/repos/webmstk/qaa/forks","keys_url":"https://api.github.com/repos/webmstk/qaa/keys{/key_id}","collaborators_url":"https://api.github.com/repos/webmstk/qaa/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/webmstk/qaa/teams","hooks_url":"https://api.github.com/repos/webmstk/qaa/hooks","issue_events_url":"https://api.github.com/repos/webmstk/qaa/issues/events{/number}","events_url":"https://api.github.com/repos/webmstk/qaa/events","assignees_url":"https://api.github.com/repos/webmstk/qaa/assignees{/user}","branches_url":"https://api.github.com/repos/webmstk/qaa/branches{/branch}","tags_url":"https://api.github.com/repos/webmstk/qaa/tags","blobs_url":"https://api.github.com/repos/webmstk/qaa/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/webmstk/qaa/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/webmstk/qaa/git/refs{/sha}","trees_url":"https://api.github.com/repos/webmstk/qaa/git/trees{/sha}","statuses_url":"https://api.github.com/repos/webmstk/qaa/statuses/{sha}","languages_url":"https://api.github.com/repos/webmstk/qaa/languages","stargazers_url":"https://api.github.com/repos/webmstk/qaa/stargazers","contributors_url":"https://api.github.com/repos/webmstk/qaa/contributors","subscribers_url":"https://api.github.com/repos/webmstk/qaa/subscribers","subscription_url":"https://api.github.com/repos/webmstk/qaa/subscription","commits_url":"https://api.github.com/repos/webmstk/qaa/commits{/sha}","git_commits_url":"https://api.github.com/repos/webmstk/qaa/git/commits{/sha}","comments_url":"https://api.github.com/repos/webmstk/qaa/comments{/number}","issue_comment_url":"https://api.github.com/repos/webmstk/qaa/issues/comments{/number}","contents_url":"https://api.github.com/repos/webmstk/qaa/contents/{+path}","compare_url":"https://api.github.com/repos/webmstk/qaa/compare/{base}...{head}","merges_url":"https://api.github.com/repos/webmstk/qaa/merges","archive_url":"https://api.github.com/repos/webmstk/qaa/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/webmstk/qaa/downloads","issues_url":"https://api.github.com/repos/webmstk/qaa/issues{/number}","pulls_url":"https://api.github.com/repos/webmstk/qaa/pulls{/number}","milestones_url":"https://api.github.com/repos/webmstk/qaa/milestones{/number}","notifications_url":"https://api.github.com/repos/webmstk/qaa/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/webmstk/qaa/labels{/name}","releases_url":"https://api.github.com/repos/webmstk/qaa/releases{/id}","created_at":"2015-05-30T18:00:10Z","updated_at":"2015-05-30T18:01:36Z","pushed_at":"2015-10-19T10:00:41Z","git_url":"git://github.com/webmstk/qaa.git","ssh_url":"git@github.com:webmstk/qaa.git","clone_url":"https://github.com/webmstk/qaa.git","svn_url":"https://github.com/webmstk/qaa","homepage":null,"size":564,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/webmstk/qaa/pulls/10"},"html":{"href":"https://github.com/webmstk/qaa/pull/10"},"issue":{"href":"https://api.github.com/repos/webmstk/qaa/issues/10"},"comments":{"href":"https://api.github.com/repos/webmstk/qaa/issues/10/comments"},"review_comments":{"href":"https://api.github.com/repos/webmstk/qaa/pulls/10/comments"},"review_comment":{"href":"https://api.github.com/repos/webmstk/qaa/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/webmstk/qaa/pulls/10/commits"},"statuses":{"href":"https://api.github.com/repos/webmstk/qaa/statuses/cef552a482596729904674e204be21d0d68888f3"}}}}