Contains
This Ktor backend server is for job searching application "Found me". This application allows for employers to search for new employees in database. Where they created their profile. Employers can sort all users in categories, and recieve list of users in those specific categories. Employers can sort list even further sorting users by keywords. When they open users profile they recieve information about that single user.
This server :
- Provides secure way to save users password (Hash and Salt password encryption)
- Provides precise Authentication and Authorization using JWT Auth
- Allows you to upload pictures via multipart request
- Is built using KOIN dependency injection
This application is built in IntelliJ IDEA 2021.1.2 (Community Edition )(Artic Fox) using :
- Ktor - For backend creation
- MongoDB - For database
- KMongo - Kotlin toolkit for MongoDB
- Kotlin - Main development language
- Coroutines - for making asynchronous tasks
- JWT (Json Web Tokens) - For safe authorization
- Koin - For dependency injection
- Gson - for serialization with Json
- Commons Codec - for security
- Truth - For making fluent assortations in testing
For testing routes :
For observing database :
-
You need to install IntelliJ IDEA version 2012.1.2 or newer you can find installation in : IntelliJ IDEA
-
For testing routes you will need Postman you can download it here : Postman
-
For observing database data you will need MongoDB Compass, you can download it here : MongoDB Compass
- Clone repository using :
-
IntelliJ IDE file -> New -> Project from version control... And enter this followin in URL
https://github.com/OzolsUgis/JobSearchingServer
-
Using terminal
git clone https://github.com/OzolsUgis/JobSearchingServer.git
-
For configuration you must create your
application.conf
file :In resources folder create new file and name it
application.conf
and in this folder add following :deployment { port = // Here you need to assign empty port default is 8080 port = ${?PORT} } application { modules = [ com.ugisozols.ApplicationKt.module ] } } jwt { issuer = // Here you assign issuer domain = // Here you assign domain audience = //Here you assign audience secret = // Here you assign secret realm = // Here you assign realm }
!!! NOTE : You should never share this file with your JWT secret in it. That's why we put this
application.conf
in.gitignore
If you dont understand what jwt properties are you can look up for information in Json Web Tokens
-
This example will show how to register user:
For this request you will need CreateAccountRequest attached to your endpoint
"api/user/create"
data class CreateAccountRequest( val email : String, val password : String, val confirmedPassword : String )
You can do it with Postman using JSON
{ "email":"[email protected]", "password":"ThisIsTestPassword", "confirmedPassword":"ThisIsTestPassword" }
! Email string need to contain
@
and.
chars, if not there will be error.! Passord must be atleast 8 units long.
When you send request you will recieve response like following or any other response if there is some error. You can see all errors in
ApiResponses
object{ "successful": true, "message": "Account Created" }
And this is how it looks like in DB, you can observe it in MongoDB compass
-
This example will show how to login in users account:
In this example you will need
AccountRequest
data class AccountRequest( val email : String, val password : String )
{ "email":"[email protected]", "password":"ThisIsTestPassword" }
When you will send this request you will recieve
MainApiResponse
where indata
field is specifiedAuthResponse
{ "successful": true, "data": { "userId": "618cf7fb61c5875f146e0bbb", "email": "[email protected]", "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJtYWluIiwiaXNzIjoiaHR0cDovLzAuMC4wLjA6ODA4MC8iLCJleHAiOjE2NjgxNjU1NTcsInVzZXJJZCI6IjYxOGNmN2ZiNjFjNTg3NWYxNDZlMGJiYiIsImVtYWlsIjoiNjE4Y2Y3ZmI2MWM1ODc1ZjE0NmUwYmJiIn0.bCofF0EkYgZOwik3gezUPols6gUTVpopUj5jmYEsrng" // Users token for authorization } }
-
Get users profile functionality seperates in 2 pieces (Get public profile, and Get private profile)
** Public profile is response what unauthorized user gets when pass in UsersId for query
** Private profile is when authorized user access hes own profile
In this example, authorized user access hes own profile:
-
You will need: QueryParameter which contains UserID, you can get that in successful login response
Assign users id to request in Postman you need to specify
BASE_URL
withRoute
. and as a request select GET requestTo specify userID in params block write KEY
userId
and VALUE618cf7fb61c5875f146e0bbb
, like you see in example above - This value is user id what you got from successful login request -
To access your own profile you need to pass Authorization security for that we need addHeaders to our request, that contains our TOKEN
In Headers block you need to specify KEY
Authorization
and VALUEBearer //Input token here//
!!! Check if between Bearer and token is only one white space
Response will be Empty User in
ProfileReponse
data class ProfileResponse( val id : String, val name : String, val lastName : String, val profession : String, val profileImageUrl : String?, val instagramUrl : String?, val linkedInUrl : String?, val githubUrl : String?, val bio : String?, val experience : Int?, val education : Education?, val skills : List<Skills> = listOf(), val currentJobState : CurrentJobState? = null, val profileUpdateDate : Long?, val keywords : List<Keywords> = listOf(), val category : Categories? )
-
This will be multipart put request where you can send Form Data (TEXT & FILE) for updating user profile information and picture
Outdated user looks like this :
To update user in Postman you must do following :
-
Specify user id in Params block you want to update in Query parameter
As a KEY insert
userId
and VALUE insert userId -
Add authorization header in Headers block
As a KEY insert
Authorization
and in VALUE field insertBearer //insert token here//
-
Add Body in Body Form-data:
As a KEY you must select type TEXT and insert key
profile_update
. And in VALUE you need to pass JSON data string. Like following:{ "id": "618689bd3f4886646510390b", "name": "Peter", "lastName": "Davis", "education":{"name": "Google Associate android developer "}, "profession": "Backend Developer", "experience" : 3, "profileImageUrl": "http://192.168.8.103:8080/profile_pictures/default_profile_picture.png", "instagramUrl": "Test web page", "linkedInUrl": "Test web page", "githubUrl": "Test web page", "bio": "Want to start job in some great IT company, my strengths are Backend development in Ktor using Kotlin language.", "skills": [ { "name": "Java" }, { "name": "Kotlin" }, { "name": "C#" } ], "keywords": [{"name":"Android"},{"name":"Java"}], "category": { "name": "IT" } }
If you want to change your profile picture you must attach another KEY
picture_update
of type File and upload file.After request you can check your data in MongoDB Compass and it should look like this
Ugis Ozols - [email protected] , LinkedIn - www.linkedin.com/in/uģis-ozols-2192a8226
Project Link - https://github.com/OzolsUgis/JobSearchingServer
-