From 189c0d27c97f8396c92ea9c4d2623594a27b99e8 Mon Sep 17 00:00:00 2001 From: rt00492 <rt00492@surrey.ac.uk> Date: Tue, 26 Apr 2022 15:21:09 +0100 Subject: [PATCH] added retriving emails --- README.md | 4 ++++ app/controllers/auth_controller.rb | 11 +++++++++++ config/routes.rb | 1 + 3 files changed, 16 insertions(+) diff --git a/README.md b/README.md index 7db80e4..579e57a 100644 --- a/README.md +++ b/README.md @@ -22,3 +22,7 @@ Things you may want to cover: * Deployment instructions * ... + +login curl + +curl -d '{"user": {"email":"test@surrey.ac.uk", "password":"123456"}}' -H "Content-Type: application/json" -X POST localhost:3000/api/login -i \ No newline at end of file diff --git a/app/controllers/auth_controller.rb b/app/controllers/auth_controller.rb index 831a1b0..3c3f14c 100644 --- a/app/controllers/auth_controller.rb +++ b/app/controllers/auth_controller.rb @@ -12,4 +12,15 @@ class AuthController < ApplicationController def auth_fail render json: { message: 'Failed to Authenticate User.'} end + + def get_email + puts params + if authenticate_user! + puts "lolol" + puts params + render json: {email: User.find_by(id: params["id"]).email} + else + auth_fail + end + end end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index be254be..1ec2497 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,6 +5,7 @@ Rails.application.routes.draw do end post 'auth', to: 'auth#access_check' + post 'auth/email', to: 'auth#get_email' devise_for :users, defaults: { format: :json }, -- GitLab