test
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
018d905b6c
commit
aeca340c8d
@ -1,94 +1,99 @@
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:postgres/postgres.dart';
|
||||
|
||||
class AccountsToPostgres{
|
||||
final connection = PostgreSQLConnection("localhost", 5432, 'passworld',username: 'pass',password: '1p2a3s4s5');
|
||||
|
||||
AccountsToPostgres(){
|
||||
class AccountsToPostgres {
|
||||
/* Dev
|
||||
final connection = PostgreSQLConnection("localhost", 5432, 'passworld',
|
||||
username: 'pass', password: '1p2a3s4s5');
|
||||
*/
|
||||
|
||||
// Production
|
||||
final connection = PostgreSQLConnection(
|
||||
Platform.environment["ENV_DB_SERVER"]!,
|
||||
5432,
|
||||
Platform.environment["ENV_DB_DATABASE"]!,
|
||||
username: Platform.environment["ENV_DB_USER"],
|
||||
password: Platform.environment["ENV_DB_PASSWORD"]);
|
||||
|
||||
AccountsToPostgres() {
|
||||
initConnection();
|
||||
}
|
||||
|
||||
void initConnection()async{
|
||||
await connection.open().then((value){
|
||||
void initConnection() async {
|
||||
await connection.open().then((value) {
|
||||
print("PostgreSQL connection opened");
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void create(String id,String hash,String salt,List<String> twoFaStr, File passwordFile ) async {
|
||||
List<int> passwordBlob = utf8.encode( await passwordFile.readAsString(encoding: utf8));
|
||||
|
||||
|
||||
connection.query("INSERT INTO \"Account\" VALUES(@id,@hash,@salt,@twofa,@passwords)",substitutionValues: {
|
||||
"id" : id,
|
||||
"hash" : hash,
|
||||
"salt" : salt,
|
||||
"twofa" : twoFaStr,
|
||||
"passwords" : passwordBlob
|
||||
});
|
||||
void create(
|
||||
String email, String hash, String salt, List<String> twoFaStr) async {
|
||||
connection.query(
|
||||
"INSERT INTO \"Account\" VALUES(@id,@hash,@salt,@twofa,@passwords)",
|
||||
substitutionValues: {
|
||||
"id": email,
|
||||
"hash": hash,
|
||||
"salt": salt,
|
||||
"twofa": twoFaStr
|
||||
});
|
||||
print("Account succesfully created");
|
||||
}
|
||||
|
||||
@override
|
||||
Future<String> selectHashById(String id) async {
|
||||
List<List<dynamic>> results = await connection.query("SELECT hash FROM \"Account\" WHERE id=@identifiant",substitutionValues: {
|
||||
"identifiant" : id
|
||||
});
|
||||
|
||||
connection.close();
|
||||
List<List<dynamic>> results = await connection.query(
|
||||
"SELECT hash FROM \"Account\" WHERE id=@identifiant",
|
||||
substitutionValues: {"identifiant": id});
|
||||
|
||||
return results[0][0];
|
||||
}
|
||||
|
||||
@override
|
||||
void updatePass(String identifiant,String hash,String salt) async {
|
||||
if(selectHashById(identifiant)==null){
|
||||
void updatePass(String identifiant, String hash, String salt) async {
|
||||
if (selectHashById(identifiant) == null) {
|
||||
return;
|
||||
}else{
|
||||
await connection.query("UPDATE \"Account\" SET hash=@h, salt=@s WHERE id=@identifiant",substitutionValues: {
|
||||
"identifiant" : identifiant,
|
||||
"h" : hash,
|
||||
"s" : salt
|
||||
});
|
||||
} else {
|
||||
await connection.query(
|
||||
"UPDATE \"Account\" SET hash=@h, salt=@s WHERE id=@identifiant",
|
||||
substitutionValues: {
|
||||
"identifiant": identifiant,
|
||||
"h": hash,
|
||||
"s": salt
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void updateFilePass(String identifiant, File passwordFile) async{
|
||||
List<int> passwordBlob = utf8.encode( await passwordFile.readAsString(encoding: utf8));
|
||||
void updateFilePass(String identifiant, File passwordFile) async {
|
||||
List<int> passwordBlob =
|
||||
utf8.encode(await passwordFile.readAsString(encoding: utf8));
|
||||
|
||||
if(selectHashById(identifiant)==null){
|
||||
if (selectHashById(identifiant) == null) {
|
||||
return;
|
||||
}else{
|
||||
await connection.query("UPDATE \"Account\" SET passwords=@p WHERE id=@identifiant",substitutionValues: {
|
||||
"identifiant" : identifiant,
|
||||
"p" : passwordBlob
|
||||
});
|
||||
} else {
|
||||
await connection.query(
|
||||
"UPDATE \"Account\" SET passwords=@p WHERE id=@identifiant",
|
||||
substitutionValues: {"identifiant": identifiant, "p": passwordBlob});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void updateTwoFa(String identifiant,List<String> tfa) async {
|
||||
void updateTwoFa(String identifiant, List<String> tfa) async {
|
||||
List<String> twoFaStr = List.empty(growable: true);
|
||||
|
||||
if(selectHashById(identifiant)==null){
|
||||
if (selectHashById(identifiant) == null) {
|
||||
return;
|
||||
}else{
|
||||
await connection.query("UPDATE \"Account\" SET twofa=@tfa WHERE id=@identifiant",substitutionValues: {
|
||||
"identifiant" : identifiant,
|
||||
"tfa" : tfa
|
||||
});
|
||||
}
|
||||
} else {
|
||||
await connection.query(
|
||||
"UPDATE \"Account\" SET twofa=@tfa WHERE id=@identifiant",
|
||||
substitutionValues: {"identifiant": identifiant, "tfa": tfa});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@override
|
||||
void DeleteById(String id) async{
|
||||
await connection.query("DELETE FROM \"Account\" WHERE id=@identifiant",substitutionValues: {
|
||||
"identifiant" : id
|
||||
});
|
||||
void DeleteById(String id) async {
|
||||
await connection.query("DELETE FROM \"Account\" WHERE id=@identifiant",
|
||||
substitutionValues: {"identifiant": id});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'dart:convert';
|
||||
|
||||
void main() async {
|
||||
String base1 =
|
||||
'https://codefirst.iut.uca.fr/containers/passworld-api-remiarnal';
|
||||
|
||||
String base2 = 'localhost:8080';
|
||||
|
||||
Uri baseURL = Uri.parse("$base2/auth");
|
||||
String body = """
|
||||
{
|
||||
"mail" : "haha",
|
||||
"password" : "haha"
|
||||
}
|
||||
""";
|
||||
|
||||
var res = await http.post(baseURL, body: body);
|
||||
print(res.body);
|
||||
}
|
Loading…
Reference in new issue