Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <cffunction name="Login" access="remote" httpMethod="POST" restpath="login" returntype="struct">
- <cfargument name="email" type="string" required="true" restargsource="form">
- <cfargument name="password" type="string" required="true" restargsource="form">
- <cfheader name="Access-Control-Allow-Origin" value="*">
- <cfheader name="Access-Control-Allow-Header" value="poopoo">
- <cfheader name="Content-Type" value="application/json; charset=utf-8">
- <cfheader name="pooopoo" value="poopoo">
- <cfset epoch = round(now().getTime() / 1000) />
- <cfquery name="checkUser" datasource="#Application.PrimaryDatasource#">
- SELECT *
- FROM Internet_Users
- WHERE
- User_Email = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.email#" />
- AND User_Pass = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.password#" />
- </cfquery>
- <cfif checkUser.recordCount gt 0>
- <cfset payload.success = true />
- <cfelse>
- <cfset abortRequest(
- 401,
- "Unauthorized",
- "Username or password is incorrect",
- 401
- ) />
- </cfif>
- <cfset jwt = new com.system.jwt(application.JWTSecret)>
- <cfset tokenPayload = {
- 'iat': epoch,
- 'exp': epoch + (30 * 60),
- 'email': arguments.email,
- 'password': arguments.password
- } />
- <cfset token = jwt.encode(tokenPayload) />
- <cfset payload.data = token />
- <cfreturn payload />
- </cffunction>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement