1
使用Devise
我想從註冊頁面複製登錄表單的行爲。設計:如何從註冊表單登錄用戶?
因此,如果用戶存在於數據庫中,並且用戶輸入的密碼與數據庫中用戶的密碼相匹配,則用戶應自動登錄到應用程序。
- 用戶到達現場並完成申請表單
- 登記控制器實現了用戶在數據庫中存在
- 應用發生在
下面的代碼提交的細節和體徵用戶覆蓋默認的註冊控制器,但是就我所做的而言。我嘗試過各種方法來從這裏調用sign_in方法,但它通常不夠用。
class RegistrationsController < Devise::RegistrationsController
def new
super
end
def create
build_resource(sign_up_params)
if User.exists?
Devise::SessionsController.new.create
# sign_in @user
# # self.resource = warden.authenticate!(auth_options)
# set_flash_message(:notice, :signed_in) if is_flashing_format?
# sign_in(resource_name, resource)
# yield resource if block_given?
# respond_with resource, :location => after_sign_in_path_for(resource)
# # set_flash_message :notice, :"user already exists"
# # sign_in(resource_name, resource)
# # respond_with resource, :location => after_sign_in_path_for(resource)
end
if resource.save
yield resource if block_given?
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_flashing_format?
sign_up(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format?
expire_data_after_sign_in!
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
set_flash_message :notice, :"failed to login"
clean_up_passwords resource
respond_with resource
end
end
def update
super
end
end
uhm - 你想自動登錄該用戶,如果提供了電子郵件,已經存在於數據庫中? –
@renepaulokat我認爲這個想法是如果他們的電子郵件和密碼都與數據庫中存在的用戶相匹配,就會自動爲用戶簽名。 –