Class: Faceauth::FacesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Faceauth::FacesController
- Defined in:
- app/controllers/faceauth/faces_controller.rb
Constant Summary collapse
- MODEL =
Reading configuration settings to identify model being used in devise configuration to manage users base.
Faceauth.model_name.camelize.constantize
Instance Method Summary collapse
-
#create ⇒ Object
This method handles the picture recieved from Webcam.
-
#new ⇒ Object
Initializing user object.
Instance Method Details
#create ⇒ Object
This method handles the picture recieved from Webcam. Saves the picture and invoke facial recongition system by comparing two pictures by identifying the user.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/faceauth/faces_controller.rb', line 18 def create @user = MODEL.find_by(Faceauth.email_column.to_sym => params[:email]) data = request.raw_post tmp_file = "#{Rails.root}/tmp/#{@user.email}_auth_source.png" File.open(tmp_file, 'wb') do |f| f.write(data) end image = MiniMagick::Image.open(tmp_file) if @user.present? && !@user.send("#{Faceauth.signup_picture_column.to_sym}").blank? @user.send("#{Faceauth.signin_picture_column.to_sym}=", image) @user.save File.delete(tmp_file) if File.exist?(tmp_file) request_uri = "#{request.protocol}#{request.host}" response = Faceauth::Authenticate.login(@user, request_uri) if !response.blank? && response["verified"] @user.reload sign_in(@user) render json: {message: "Authentication Successful", status: "success", location: main_app.try(Faceauth.redirect_url)} else render json: {message: "Verification Failed. Please try again!", status: "failed"} end else render json: {message: "Sorry! System didn't recognize you'", status: "failed"} end end |
#new ⇒ Object
Initializing user object
12 13 14 |
# File 'app/controllers/faceauth/faces_controller.rb', line 12 def new @user = MODEL.new end |