Friday, 24 January 2020

React




1- npm install -g create-react-app

      then occur this error Error: EACCES: permission denied, symlink '../lib/node_modules/create-
       react-app/index.js' -> '/usr/bin/create-react-app'

       then use this sudo npm install -g create-react-app

2- npm install -g create-react-app

       Error:- react-scripts: not found
       fix:- yarn install or nvm version not support




Github Dump

GitHub

1- When you don't know what is the server port of PC 
        use this cmd-: ifconfig
            => sudo apt install net-tools (ifconfig inet 192.168.1.3)

2- Create a new branch on github   git checkout -b Dummy
       
        output:-  M   db/schema.rb
                      Switched to a new branch 'Dummy'

3- When you switched to exist branch   git checkout dev
        output:-  M   db/schema.rb
                       Switched to branch 'dev'

4- How to import dump database 
      pg_restore --verbose --clean --no-acl --no-owner -h localhost -U postgres -d database_name       
       latest.dump

===================================================================================

1- How to fetch GitHub Branch
   => git fetch -t
      => github username: kapilgoyal6
       => Access Token: 7a5f01b52a9ab0f7069604154686b4a4046ac7a0

2- How to List Branch on Git?

   * The command to list all branches in local and remote repositories is:
          git branch -a

   * If you require only listing the remote branches from Git Bash then use this command:
         git branch -r
   * You may also use the show-branch command for seeing the branches and their commits as 
      follows:
        git show-branch



Thursday, 23 January 2020

Gem devise

Gem devise

1gem 'devise'
   gem 'bootstrap', '~> 4.0.0.alpha3'
2. Run $ bundle install
3. Add Bootstrap’s styles:  stylesheets/application.scss 
         @import "bootstrap";


4.   Run the following commands to install Devise, generate a new User model,
      and copy views for further cutomization: 
          $ rails generate devise:install
       $ rails generate devise User
       $ rails generate devise:views
       $ rails db:migrate
 
 5. Now restrict access to all pages of the site to authenticated users only:
     application_controller.rb  => 

       
class ApplicationController < ActionController::Base

 before_action :authenticate_user!

 before_action :configure_permitted_parameters, if: :devise_controller?

 protected

  def configure_permitted_parameters
   
   devise_parameter_sanitizer.permit(:sign_up) {|u| u.permit(:email,:password,:password_confirmation,:first_name,:last_name,:company_id,:user_role_id,
          :start_date,:end_date,:monthly_charge,:notes,:image,:active)}

   devise_parameter_sanitizer.permit(:account_update) {|u| u.permit(:email,:password,:password_confirmation,:first_name,:last_name,:company_id,:user_role_id,
          :start_date,:end_date,:monthly_charge,:notes,:image,:active, :current_password)}
  end
end 

6. Add this code to (Layouts/application.html.erb)
          <% if user_signed_in? %>
             Logged in as <strong><%= current_user.email %></strong>
             <%= link_to 'Edit Profile', edit_user_registration_path, :class=>'navbar-link' %> /
             <%= link_to 'Logout',   destroy_user_session_path, :class=>'navbar-link' %> / 
          <%  else  %>
            <%= link_to "Sign up", new_user_registration_path, :class=>'navbar-link' %> |
            <%= link_to "Login", new_user_session_path, :class=>'navbar-link' %>
         <%  end %> 

 
 
 
 

reCaptcha

ReCaptcha

1. Open your Gemfile and add this code:
        gem "recaptcha", require: "recaptcha/rails"

2. Now run bundle
     bundle install

3- Then I inherited devise registration controller and overridden the create method of it.
        
  1. class User::RegistrationsController < Devise::RegistrationsController
  2. #
  3. # Other Codes
  4. def create
  5. ## To build the resource
  6. build_resource(sign_up_params)
  7. ## Verifying Captcha
  8. if verify_recaptcha(model: resource)
  9. super
  10. else
  11. render 'new'
  12. end
  13. end
  14. #
  15. # Other Codes
  16. end

4. Now you need to get the public and secret key by registering into Google recaptcha account.
    

    1-  Label - recaptcha Test
    2-  reCAPTCHA type - reCAPTCHA v2  and after select 1 option 
          ("I'm not a robot" tickbox)
    3-  Domains -  localhost, for heroku- heroku.com
   
5. Now add the configurations for recaptcha at /config/initializer/recaptcha.rb
     
  1. Recaptcha.configure do |config|
  2. config.public_key = 'Replace with your public key'
  3. config.private_key = 'Replace with private key'
  4. end

OR
                     add .env file in project source add key

 export RECAPTCHA_SITE_KEY = '6LcLFdIUAAAAAFKQUU4b3HnWYtssgTWdsnQZsVXU'
 export RECAPTCHA_SECRET_KEY = '6LcLFdIUAAAAAA4Z66WTWojY0_RsyR7DqnhtOYUf'

6. Add the recaptcha tags to app/views/devise/registrations/new
       <div><%= recaptcha_tags %></div>

7. Now we need to tell the route to go to our registration controller instead of devise registration controller. So              routes needs to be modified to:
    
       devise_for :users, :controllers => {:registrations => "user/registrations"}

Link for reCaptch:-
   

    

  Common Git Commands   Take clone of a repository git clone <remote-repository-url> ex: git clone  https://github.com/agricor/RegTech...