Skip to content

Commit

Permalink
Added special user for Apple testing
Browse files Browse the repository at this point in the history
  • Loading branch information
nrubin29 committed Jan 18, 2022
1 parent e518ec4 commit d9fcc32
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions server/lib/services/auth_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ 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]);

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);
}
Expand All @@ -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();
}
}
}

Expand Down

0 comments on commit d9fcc32

Please sign in to comment.