How to Implement User Login in Peatio

How to Implement User Login in Peatio

11 Mar 2021
How to Implement User Login in Peatio

Being my first ever live project, I wanted to concentrate on every aspect and detail to deliver my best. The Project was Peatio, which is a core, open-source Crypto-currency, and digital asset exchange platform is built and implemented on the Rails framework (Ruby on Rails) and other advanced technologies and server components. It was a huge project, with a prominent client which meant a huge responsibility as a newbie. I was fortunate enough to get a supportive mentor throughout the project. 

Technologies Stack for the Project:

  • Frontend technologies:

HTML, CSS, Angular JS, CoffeScript, JavaScript, Jquery, Bootstrap, AJAX etc.

  • Backend technologies:

Ruby - 2.5.1, Rails – 4   Database – MYSQL

During this project, I worked on multiple modules but the one I found fascinating and challenging was “To Login into User’s Account”.  In this module, the admin can log in to the user’s account but in reading mode through the user's email address or id.


  • The current user session (Admin) needs to be stored after which the admin can log in to the user's account with a new session.
  •  After logging out from the user account, it should return to the same page with the stored session (Admin).
  • The user account should always open in ‘Read-only mode’.

Solving Approach:

To complete this module, I made use of the session variable. 

Step 1: - Saving the session of admin role in one session variable.

Step 2: - Fetching and save the user id in another session variable.  

Step 3: -Finally replacing the new user session variable with the current session variable by placing proper conditions to execute it in read-only mode.


def new_login
      if admin_user?  (Checking for user is already admin or not)
        flash[:notice] = 'Already a Admin User'
        redirect_to admin_path
        session[:admin_id] =   (Step 1)
        user_id = User.find_by(id: params[:id])  (Step 2)
        session[:user_id] = user_id  (Step 2)
        session[:current_id] = session[:user_id]  (Step 3)
        redirect_to root_path  (Redirect to Welcome page)

Leave a comment: