Advertisement
Guest User

Untitled

a guest
Mar 15th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. class User < ActiveRecord::Base
  2. # Include default devise modules. Others available are:
  3. # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
  4. devise :database_authenticatable, :registerable,
  5. :recoverable, :rememberable, :trackable, :validatable, :confirmable, :omniauthable
  6.  
  7. validates_presence_of :user_name, :address, :tel
  8.  
  9. # Setup accessible (or protected) attributes for your model
  10. attr_accessible :user_name, :address, :tel, :attorney_number, :email, :password, :password_confirmation, :remember_me
  11.  
  12. has_many :eclaims
  13. has_many :createdtemplates
  14.  
  15. before_create do |user|
  16. user.with_agreement = 1
  17. end
  18.  
  19. def self.find_for_google_oauth2(access_token, signed_in_resource=nil)
  20. data = access_token.info
  21. user = User.where(:email => data["email"]).first
  22.  
  23. unless user
  24. user = User.create(
  25. user_name: 'no defined',
  26. address: 'no defined',
  27. tel: 'no defined',
  28. attorney_number: nil,
  29. email: data["email"],
  30. encrypted_password: Devise.friendly_token[0,20],
  31. )
  32. end
  33. user
  34. end
  35. end
  36.  
  37. class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  38. def google_oauth2
  39. # You need to implement the method below in your model (e.g. app/models/user.rb)
  40. @user = User.find_for_google_oauth2(request.env["omniauth.auth"], current_user)
  41.  
  42. if @user.persisted?
  43. flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google"
  44. sign_in_and_redirect @user, :event => :authentication
  45. else
  46. session["devise.google_data"] = request.env["omniauth.auth"]
  47. redirect_to new_user_registration_url
  48. end
  49. end
  50. end
  51.  
  52. EFiling2::Application.routes.draw do
  53. root :to => "home#index"
  54.  
  55. devise_for :users,
  56. :path_names => { :sign_up => "register", :sign_in => "login", :sign_out => "logout" },
  57. :controllers => {
  58. :sessions => "sessions",
  59. :registrations => "registrations",
  60. :confirmations => "confirmations",
  61. :passwords => "passwords",
  62. :omniauth_callbacks => "users/omniauth_callbacks"
  63. }
  64. end
  65.  
  66. user = User.create(user_name: 'no defined', ...)
  67.  
  68. user = User.new
  69. ...
  70. user.confirm!
  71. user.save!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement