class Api::AuthController < ApplicationController
	skip_before_filter  :verify_authenticity_token
	def login
 
		username = params[:username]
    access = params[:access_code]

   	member = Member.find_by_email(username)
		if member && member.valid_password?(access)
		 	member.session_token = SecureRandom.hex 		 	 
      		if member.save
            find_user=User.find_by_id(member.user_id)
            if !find_user.nil?
               arr_user={:id => find_user.id,:name => find_user.name,:nrc => find_user.nrc,:email =>find_user.email,:is_active =>find_user.is_active,:phone =>find_user.phone,:address => find_user.address,:session_token => member.session_token} 
            end
      			@out=true,arr_user
      		else
      			@out=false,"Error occurs in login process."
      		end
      	else
      	    @out=false,"Sorry!Unauthorized user!" 
		end
	end
	def logout
      login_token = params[:session_token]
      @user = Member.find_by_session_token(login_token)
      if !@user.nil? 
          @user.session_token = nil
          if @user.save            
            return @user
          end  
      end
  end
end