Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
API Development Course Apr 2021
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sibidharan
API Development Course Apr 2021
Commits
3808e5a0
Commit
3808e5a0
authored
3 years ago
by
Sibidharan
Browse files
Options
Downloads
Patches
Plain Diff
API for Notes - start
parent
3c4645a1
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
api/index.php
+18
-41
18 additions, 41 deletions
api/index.php
api/lib/Auth.class.php
+2
-0
2 additions, 0 deletions
api/lib/Auth.class.php
api/lib/Database.class.php
+20
-0
20 additions, 0 deletions
api/lib/Database.class.php
api/lib/Signup.class.php
+28
-0
28 additions, 0 deletions
api/lib/Signup.class.php
with
68 additions
and
41 deletions
api/index.php
+
18
−
41
View file @
3808e5a0
<?php
error_reporting
(
E_ALL
^
E_DEPRECATED
);
require_once
(
"REST.api.php"
);
require_once
(
"lib/Database.class.php"
);
require_once
(
"lib/Signup.class.php"
);
class
API
extends
REST
{
public
$data
=
""
;
private
$DB_SERVER
=
"localhost"
;
private
$DB_USER
=
"root"
;
private
$DB_PASSWORD
=
""
;
private
$DB_NAME
=
"apis"
;
private
$db
=
NULL
;
public
function
__construct
(){
parent
::
__construct
();
// Init parent contructor
//read database config from ../../env.json
/*
file env.json
{
"database": "apis",
"username": "root",
"password": "",
"server": "localhost"
}
*/
$config_json
=
file_get_contents
(
'../../env.json'
);
$config
=
json_decode
(
$config_json
,
true
);
$this
->
DB_SERVER
=
$config
[
'server'
];
$this
->
DB_USER
=
$config
[
'username'
];
$this
->
DB_PASSWORD
=
$config
[
'password'
];
$this
->
DB_NAME
=
$config
[
'database'
];
$this
->
dbConnect
();
// Initiate Database connection
}
/*
Database connection
*/
private
function
dbConnect
(){
if
(
$this
->
db
!=
NULL
)
{
return
$this
->
db
;
}
else
{
$this
->
db
=
mysqli_connect
(
$this
->
DB_SERVER
,
$this
->
DB_USER
,
$this
->
DB_PASSWORD
,
$this
->
DB_NAME
);
if
(
!
$this
->
db
)
{
die
(
"Connection failed: "
.
mysqli_connect_error
());
}
else
{
return
$this
->
db
;
}
}
parent
::
__construct
();
// Init parent contructor
$this
->
db
=
Database
::
getConnection
();
// Initiate Database connection
}
/*
...
...
@@ -128,6 +91,20 @@
return
bin2hex
(
$bytes
);
}
private
function
gen_hash
(){
if
(
isset
(
$this
->
_request
[
'pass'
])){
$s
=
new
Signup
(
""
,
$this
->
_request
[
'pass'
],
""
);
$hash
=
$s
->
hashPassword
();
$data
=
[
"hash"
=>
$hash
,
"val"
=>
$this
->
_request
[
'pass'
],
"verify"
=>
password_verify
(
$this
->
_request
[
'pass'
],
$hash
)
];
$data
=
$this
->
json
(
$data
);
$this
->
response
(
$data
,
200
);
}
}
...
...
This diff is collapsed.
Click to expand it.
api/lib/Auth.class.php
0 → 100644
+
2
−
0
View file @
3808e5a0
<?php
This diff is collapsed.
Click to expand it.
api/lib/Database.class.php
0 → 100644
+
20
−
0
View file @
3808e5a0
<?php
class
Database
{
static
$db
;
public
static
function
getConnection
(){
$config_json
=
file_get_contents
(
'../../env.json'
);
$config
=
json_decode
(
$config_json
,
true
);
if
(
Database
::
$db
!=
NULL
)
{
return
Database
::
$db
;
}
else
{
Database
::
$db
=
mysqli_connect
(
$config
[
'server'
],
$config
[
'username'
],
$config
[
'password'
],
$config
[
'database'
]);
if
(
!
Database
::
$db
)
{
die
(
"Connection failed: "
.
mysqli_connect_error
());
}
else
{
return
Database
::
$db
;
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
api/lib/Signup.class.php
0 → 100644
+
28
−
0
View file @
3808e5a0
<?php
require_once
(
'Database.class.php'
);
class
Signup
{
private
$username
;
private
$password
;
private
$email
;
private
$db
;
public
function
__construct
(
$username
,
$password
,
$email
){
$this
->
db
=
Database
::
getConnection
();
$this
->
username
=
$username
;
$this
->
password
=
$password
;
$this
->
email
=
$email
;
}
public
function
getInsertID
(){
}
public
function
hashPassword
(){
return
password_hash
(
$this
->
$password
,
PASSWORD_BCRYPT
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment