Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "flutter_application_1",
"cwd": "flutter_application_1",
"request": "launch",
"type": "dart"
},
{
"name": "flutter_application_1 (profile mode)",
"cwd": "flutter_application_1",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "flutter_application_1 (release mode)",
"cwd": "flutter_application_1",
"request": "launch",
"type": "dart",
"flutterMode": "release"
}
]
}
Binary file modified api/__pycache__/api.cpython-311.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ def get_water_level():
return '', 204

if __name__ == '__main__':
app.run(debug=True)
app.run(host='0.0.0.0', port=5000, debug=True, threaded=True)
177 changes: 177 additions & 0 deletions api/api_SignIn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
from flask import Flask, request, jsonify
import influxdb_client
from influxdb_client.client.write_api import SYNCHRONOUS
import hashlib



app = Flask(__name__)
bucket = "myusers"
org = "2cpProject"
token = "m-RlxCAkiz-d4tvcVFll9ml5pNpB654vi2XtsSx_2pV_OCASVCEF6naraD8JErGcOsp6qH56nD7NTWnYcPpeCA=="
# Store the URL of your InfluxDB instance
url = "http://localhost:8086"

client = influxdb_client.InfluxDBClient(
url=url,
token=token,
org=org
)
query_api = client.query_api()


@app.route('/signup', methods=['POST'])
def signup():
data = request.json
required_fields = ['full_name', 'tank_number', 'phone_number',
'password', 'confirm_password']
for field in required_fields:
if (data.get(field) == ""):
field = field.replace("_", " ")
return jsonify({'error': f'{field} is required'}), 400

full_name = data['full_name']
tank_number = int(data['tank_number'])
phone_number = int(data['phone_number'])
password = (data['password'])
confirm_password = (data['confirm_password'])

if password != confirm_password:
return jsonify({'error': 'Passwords do not match'}), 400

# check if the tank number or the phone number already exist in the users measurement

query = f'from(bucket:"{bucket}") \
|> range(start: -1h) \
|> filter(fn: (r) => r["_measurement"] == "users1") \
|> filter(fn: (r) => r["_field"] == "phone_number" )\
|> filter(fn: (r) => r["_value"] == {phone_number})'

result = query_api.query(org=org, query=query)
if len(result) > 0:
return jsonify({'error': 'User with this phone number already exists'}), 400

# create new user
write_api = client.write_api(write_options=SYNCHRONOUS)

data = [
{
"measurement": "users1",
"tags": {
"org": org,
"bucket": bucket
},
"fields": {
"full_name": full_name,
"tank_number": tank_number,
"phone_number": phone_number,
"password_hash": password
}
}
]

write_api.write(bucket=bucket, org=org, record=data)

return jsonify({'message': 'User created successfully'}), 201


@app.route('/add_tank_cuboid', methods=['POST'])
def add_tank_cuboid():
data = request.json
required_fields = ['tank_number',
'tank_height', 'base_width', 'base_length']
for field in required_fields:
if (data.get(field) == ""):
field = field.replace("_", " ")
return jsonify({'error': f'{field} is required'}), 400

tank_number = int(data['tank_number'])
tank_volume = float(data['tank_height'])*float(data['base_width'])*float(data['base_length'])

# Store the tank information in the 'tanks' measurement
write_api = client.write_api(write_options=SYNCHRONOUS)

data = [
{
"measurement": "tanks",
"tags": {
"org": org,
"bucket": bucket
},
"fields": {
"tank_number": tank_number,
"tank_volume": tank_volume
}
}
]

write_api.write(bucket=bucket, org=org, record=data)

return jsonify({'message': 'Tank information stored successfully'}), 201


@app.route('/add_tank_cylinder', methods=['POST']) # for the cylinder shape
def add_tank_cylinder():
data = request.json


required_fields = ['tank_number',
'tank_height', 'tank_width']
for field in required_fields:
if (data.get(field) == ""):
field = field.replace("_", " ")
return jsonify({'error': f'{field} is required'}), 400

tank_number = int(data['tank_number'])
tank_volume = float(data['tank_height'])*3.14*(float(data['tank_width'])/2)**2

# Store the tank information in the 'tanks-cylinder' measurement
write_api = client.write_api(write_options=SYNCHRONOUS)

data = [
{
"measurement": "tanks",
"tags": {
"org": org,
"bucket": bucket
},
"fields": {
"tank_number": tank_number,
"tank_volume": tank_volume
}
}
]

write_api.write(bucket=bucket, org=org, record=data)

return jsonify({'message': 'Tank information stored successfully'}), 201

@app.route('/signin', methods=['POST'])
def signin():
data = request.json
required_fields = ['phone_number', 'password']
for field in required_fields:
if (data.get(field) == ""):
field = field.replace("_", " ")
return jsonify({'error': f'{field} is required'}), 400

phone_number = int(data['phone_number'])
password = (data['password'])

query = f'from(bucket:"{bucket}") \
|> range(start: -1h) \
|> filter(fn: (r) => r["_measurement"] == "users1") \
|> pivot(rowKey:["_time"], columnKey:["_field"], valueColumn:"_value")\
|> filter(fn: (r) => r.password_hash == "{password}" and r.phone_number == {phone_number})'

result = query_api.query(org=org, query=query)

if len(result) > 0:
tank_number = result[0].get('tank_number')
return jsonify({'tank_number': str(tank_number)}), 200
else:
return jsonify({'error': 'Incorrect password or phone number'}), 401


if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True, threaded=True)
Empty file added api/py
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@mipmap/ic_launcher_adaptive_back"/>
<foreground android:drawable="@mipmap/ic_launcher_adaptive_fore"/>
</adaptive-icon>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added flutter_application_1/assets/cuboidshape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added flutter_application_1/assets/cylinder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added flutter_application_1/assets/icon.png
68 changes: 61 additions & 7 deletions flutter_application_1/lib/SignIn.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,66 @@ import 'package:fluid/main.dart';
import 'package:flutter/material.dart';
import 'Home.dart';
import 'SignUp.dart';
import 'dart:convert';
import 'package:http/http.dart' as http;


class LoginPage extends StatefulWidget {
@override
_LoginPageState createState() => _LoginPageState();
}

class _LoginPageState extends State<LoginPage> {
final TextEditingController _tankNumberController = TextEditingController();

final TextEditingController _phoneNumberController = TextEditingController();
final TextEditingController _passwordController = TextEditingController();
final TextEditingController _confirmpasswordController =
TextEditingController();

Future<Map<String, dynamic>> _signIn(BuildContext context) async {
final String apiUrl = "http://192.168.78.9:5000/signin";
final response = await http.post(
Uri.parse(apiUrl),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(<String, String>{
'phone_number': _phoneNumberController.text,
'password': _passwordController.text,
}),
);

final responseData = jsonDecode(response.body);

if (response.statusCode == 200) {
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => Home()),
);
return {
'signedIn': true,
'tank_number': responseData['tank_number'],
};
} else {
showDialog(
context: context,
builder: (ctx) => AlertDialog(
title: Text("An error occurred!"),
content: Text(responseData['error']),
actions: <Widget>[
ElevatedButton(
child: Text("Okay"),
onPressed: () {
Navigator.of(ctx).pop();
},
),
],
),
);
return {
'signedIn': false,
'tank_number': '',
};
}
}

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -95,9 +144,9 @@ class _LoginPageState extends State<LoginPage> {
children: [
TextField(
keyboardType: TextInputType.phone,
controller: _tankNumberController,
controller: _phoneNumberController,
decoration: InputDecoration(
hintText: 'tank number',
hintText: 'Phone number',
hintStyle: TextStyle(
fontFamily: 'Montserrat',
fontStyle: FontStyle.normal,
Expand All @@ -113,7 +162,7 @@ class _LoginPageState extends State<LoginPage> {
borderSide:
BorderSide(color: Color(0xFF789CD2), width: 1),
),
prefixIcon: Icon(Icons.water, color: Color(0xFF989898)),
prefixIcon: Icon(Icons.phone, color: Color(0xFF989898)),
),
),
SizedBox(height: 40),
Expand Down Expand Up @@ -152,7 +201,11 @@ class _LoginPageState extends State<LoginPage> {
left: 117,
top: 410,
child: ElevatedButton(
onPressed: () {},
onPressed: () async {
final result = await _signIn(context);
final bool signedIn = result['signedIn'];
final String tankNumber = result['tank_number'];
},
child: Container(
width: 112,
height: 34,
Expand Down Expand Up @@ -300,4 +353,5 @@ class CustomWavePainter extends CustomPainter {

@override
bool shouldRepaint(CustomWavePainter oldDelegate) => false;

}
Loading