Sunday, 31 October 2021

 

Common Git Commands

 

Take clone of a repository
git clone <remote-repository-url>
 
Create a branch
The branch should always be created from dev branch, for that you need to first checkout to dev branch by the following command
  • git checkout dev
  • git pull origin dev
then create the branch
  • git checkout -b <branch-name>
ex: git checkout -b feature/regtech-533
Here feature notifies that this branch is created for a feature. Similarly for creating a branch for a bug the branch name will be like bug/regtech-113
 
To see the current branch
git branch
 
To see all the branches in a repository
git branch -a
 
Pull from a branch
git pull <branch-name>
git pull origin feature/regtech-533
 
To see the status
git status
 
To see the differences made
git diff
 
staging a file or folder
git add <file or folder name>
ex: git add index.ts
 
committing the changes
git commit -m "message"
ex: git commit -m "Changes made for feature regtech-533"
 
To push the code to repository
git push origin <branch-name>
ex: git push origin feature/regtech-533
 
For Creating a pull request
After pushing the code to the repository
go to github.com repository page
Click on the contribute button below the code and press the open pull request button

Thursday, 19 August 2021

How to Update a Project Rails ('rails', '5.2.5') to 'rails', '6.1.4'

 Follow some basic step to update rails version

1. Go to the Gemfile and replace older rails version to new rails version Like 

    gem 'rails', '5.2.5' gem 'rails', '6.1.4'

    
    gem 'pg', '< 1.0.0' gem 'pg'

    ruby '2.7.1'

2.  After that Run bundle install

3. after that run this:- raile app:update 

 => when we run this cmd I have to keep the changes of these all files which are given below :-

  • bin/setup
  • bin/yarn
  • config.ru
  • config/environments/development.rb
  • config/environments/production.rb
  • config/environments/test.rb
  • config/initializers/content_security_policy.rb
  • config/initializers/new_framework_defaults_6_1.rb
  • config/initializers/permissions_policy.rb
  • db/schema.rb     
4. In this file Dockerfile.dev  FROM ruby:2.6.7 FROM ruby:2.7.1

5. In this file Dockerfile.prod

    FROM ruby:2.6.7-alpine as Builder FROM ruby:2.7.1-alpine as Builder

RUN gem install bundler:2.2.16 RUN gem install bundler:2.2.26

FROM ruby:2.6.7-alpine FROM ruby:2.7.1-alpine


go to this Url for reference :- https://github.com/pmdgithub/auth/pull/202/files

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:-
   

    

Tuesday, 10 December 2019

Shopify App (with shopify gem in rails)

Shopify App 

https://github.com/Shopify/shopify_app

1- # Create a new rails app 
        $ rails new my_shopify_app 
        $ cd my_shopify_app
 

2- # Add the gem shopify_app to your Gemfile  

          "gem 'shopify_app'"
           bundle install
         
Now we are ready to run any of the shopify_app generators. The following section explains the generators and what they can do.

3- Default Generator

The default generator will run the install, shop, and home_controller generators. This is the recommended way to start your app.
     
        $ rails generate shopify_app
 
 After run this cmd generated file list is here.

 generate  shopify_app:install
Running via Spring preloader in process 7234
     gemfile  dotenv-rails
      create  config/initializers/shopify_app.rb
      create  config/initializers/session_store.rb
      create  config/initializers/omniauth.rb
      insert  config/initializers/omniauth.rb
      create  app/views/layouts/embedded_app.html.erb
      create  app/views/layouts/_flash_messages.html.erb
      create  app/assets/javascripts/shopify_app.js
      create  app/assets/javascripts/flash_messages.js
      create  config/initializers/user_agent.rb
       route  mount ShopifyApp::Engine, at: '/'
      insert  config/environments/development.rb
    generate  shopify_app:shop_model
Running via Spring preloader in process 7254
      create  app/models/shop.rb
      create  db/migrate/20191210084729_create_shops.rb
        gsub  config/initializers/shopify_app.rb
      create  test/fixtures/shops.yml
    generate  shopify_app:authenticated_controller
Running via Spring preloader in process 7277
      create  app/controllers/authenticated_controller.rb
    generate  shopify_app:home_controller
Running via Spring preloader in process 7281
      create  app/controllers/home_controller.rb
      create  app/views/home/index.html.erb
     prepend  app/views/home/index.html.erb
       route  root :to => 'home#index'

4-  After running the generator, you will need to run rake db:migrate to add 
     tables to your database. You can start your app with bundle exec rails server 
     and install your app by visiting localhost.

5- The default and install generators have been updated to source Shopify API 
    key and secret from a .env file, which you will need to create with the 
    following format:
       SHOPIFY_API_KEY=your api key
       SHOPIFY_API_SECRET=your api secret
  
These values can be found on the "App Setup" page in the Shopify Partners Dashboard.(when you create a account on shopify and after create a app then u get api key and api secret )

6- Install Generator
        rails generate shopify_app:install

After running the install generator, you can start your app with bundle exec rails server and install your app by visiting localhost.

7- Shop Model Generator
       rails generate shopify_app:shop_model

This generator creates a shop model and a migration. This model includes the ShopifyApp::SessionStorage concern which adds two methods to make it compatible as a SessionRepository. After running this generator you'll notice the session_repository in your config/initializers/shopify_app.rb will be set to the Shop model. This means that internally ShopifyApp will try and load tokens from this model.
           identical  app/models/shop.rb
           identical  db/migrate/20191210084729_create_shops.rb
           gsub  config/initializers/shopify_app.rb
           identical  test/fixtures/shops.yml



Note that you will need to run rake db:migrate after this generator
 




8- Home Controller Generator
         rails generate shopify_app:home_controller

This generator creates an example home controller and view which fetches and displays products using the ShopifyAPI

         identical  app/controllers/home_controller.rb
         force  app/views/home/index.html.erb
         prepend  app/views/home/index.html.erb
         route  root :to => 'home#index' 


9- App Proxy Controller Generator
          rails generate shopify_app:app_proxy_controller

 This optional generator, not included with the default generator, creates the app proxy controller to handle proxy requests to the app from your shop storefront, modifies 'config/routes.rb' with a namespace route, and an example view which displays current shop information using the LiquidAPI.

           create  app/controllers/app_proxy_controller.rb
           create  app/views/app_proxy/index.html.erb
           insert  config/routes.rb

 
 10- Controllers, Routes and Views

The last group of generators are for your convenience if you want to start overriding code included as part of the Rails engine. For example by default the engine provides a simple SessionController, if you run the rails generate shopify_app:controllers generator then this code gets copied out into your app so you can start adding to it. Routes and views follow the exact same pattern.

after run this cmd create files:
      create  app/controllers/shopify_app/authenticated_controller.rb
      create  app/controllers/shopify_app/callback_controller.rb
      create  app/controllers/shopify_app/sessions_controller.rb
      create  app/controllers/shopify_app/webhooks_controller.rb

  
 11- Routes
           mount ShopifyApp::Engine, at: '/'


     * update the omniauth initializer to include a custom callback_path
 

          provider :shopify,
             ShopifyApp.configuration.api_key, 
             ShopifyApp.configuration.secret, 
             scope: ShopifyApp.configuration.scope, 
             callback_path: '/auth/shopify/callback'




  
   
Finally, note that if you do this, to add your app to a store, you must navigate to / in order to render the Enter your shop domain to log in or install this app.

          UI  (example.myshopify.com) when run localhost:3000/login

12- Custom login URL

While you can customize the login view by creating a /app/views/shopify_app/sessions/new.html.erb file, you may also want to customize the URL entirely. You can modify your shopify_app.rb initializer to provide a custom login_url

           ShopifyApp.configure do |config|
              config.login_url = 'https://my.domain.com/nested/login'
           end
 



















13- Per User Authentication 

To enable per user authentication you need to update  the omniauth.rb  initializer:

        provider :shopify,
          ShopifyApp.configuration.api_key,
          ShopifyApp.configuration.secret,
          scope: ShopifyApp.configuration.scope,
          per_user_permissions: true
 
 
The current Shopify user will be stored in the rails session at session[:shopify_user]

This will change the type of token that Shopify returns and it will only be valid for a short time. Read more about Online access here. Note that this means you won't be able to use this token to respond to Webhooks.

14- WebhooksManager

rails g shopify_app:add_webhook -t carts/update -a http://localhost:3000/webhooks/carts_update

invoke  test_unit
      create    test/jobs/carts_update_job_test.rb
      insert  config/initializers/shopify_app.rb
      insert  config/initializers/shopify_app.rb
      create  app/jobs/carts_update_job.rb


ShopifyApp can manage your app's webhooks for you if you set which webhooks you require in the initializer:

 ShopifyApp.configure do |config|
     config.webhooks = [
          {topic: 'carts/update', address: 'http://localhost:3000/webhooks 

          /carts_update', format: 'json'},
     ]

 end

15- AfterAuthenticate Job

We've also provided a generator which creates a skeleton job and updates the initializer for you:
       bin/rails g shopify_app:add_after_authenticate_job

invoke  test_unit
      create    test/jobs/shopify/after_authenticate_job_test.rb
      insert  config/initializers/shopify_app.rb
Error adding after_authenticate_job to config. Add this line manually:   config.after_authenticate_job = { job: "Shopify::AfterAuthenticateJob", inline: false }
      create  app/jobs/shopify/after_authenticate_job.rb

 

 To configure the after authenticate job update your initializer as follows:

         ShopifyApp.configure do |config|
              config.after_authenticate_job = { job:"Shopify::AfterAuthenticateJob", 
               inline: false }
         end










 

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