From d9fcc32cccd74a2484ca0f4c2fcaa23c3fda0a79 Mon Sep 17 00:00:00 2001 From: nrubin29 Date: Mon, 17 Jan 2022 23:55:35 -0800 Subject: [PATCH] Added special user for Apple testing --- server/lib/services/auth_service.dart | 33 ++++++++++++++++----------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/server/lib/services/auth_service.dart b/server/lib/services/auth_service.dart index 729d6b0..911be50 100644 --- a/server/lib/services/auth_service.dart +++ b/server/lib/services/auth_service.dart @@ -23,6 +23,10 @@ class AuthService { final loginRequest = await request.readAsObject(LoginRequest.fromJson); final username = loginRequest.username; + if (username == 'appleTest') { + return genericResponse(success: true); + } + // Delete any current pending logins. await _database .delete('PendingLogin', where: 'username = ?', whereArgs: [username]); @@ -30,7 +34,8 @@ class AuthService { final code = _generateCode(); final success = await _database .insert('PendingLogin', {'username': username, 'code': code}); - final emailSuccess = await EmailService.sendVerificationEmail(username, code); + final emailSuccess = + await EmailService.sendVerificationEmail(username, code); return genericResponse(success: success > 0 && emailSuccess); } @@ -40,23 +45,25 @@ class AuthService { final verificationRequest = await request.readAsObject(VerificationRequest.fromJson); final username = verificationRequest.username; + final code = verificationRequest.code; - final numRowsDeleted = await _database.delete('PendingLogin', - where: 'username = ? AND code = ?', - whereArgs: [username, verificationRequest.code]); + if (username != 'appleTest' || code != '1234') { + final numRowsDeleted = await _database.delete('PendingLogin', + where: 'username = ? AND code = ?', whereArgs: [username, code]); - if (numRowsDeleted == 0) { - return Response.ok(json.encode(VerificationResponse(token: null))); - } + if (numRowsDeleted == 0) { + return Response.ok(json.encode(VerificationResponse(token: null))); + } - final existingUser = await _database - .query('User', where: 'username = ?', whereArgs: [username]); + final existingUser = await _database + .query('User', where: 'username = ?', whereArgs: [username]); - if (existingUser.isEmpty) { - final userId = await _database.insert('User', {'username': username}); + if (existingUser.isEmpty) { + final userId = await _database.insert('User', {'username': username}); - if (userId <= 0) { - return Response.internalServerError(); + if (userId <= 0) { + return Response.internalServerError(); + } } }