Update user on startup
This commit is contained in:
parent
3795a0ff4d
commit
88bea3731b
@ -74,7 +74,7 @@ public class LoginActivity extends AppCompatActivity {
|
|||||||
* Wechselt zu der Dash Activity
|
* Wechselt zu der Dash Activity
|
||||||
*/
|
*/
|
||||||
private void goDash() {
|
private void goDash() {
|
||||||
if (!db.checkIfUserExists(FirebaseAuth.getInstance().getCurrentUser().getUid())) {
|
|
||||||
FirebaseInstanceId.getInstance().getInstanceId()
|
FirebaseInstanceId.getInstance().getInstanceId()
|
||||||
.addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
|
.addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
|
||||||
@Override
|
@Override
|
||||||
@ -92,14 +92,21 @@ public class LoginActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
// Get new Instance ID token
|
// Get new Instance ID token
|
||||||
String token = task.getResult().getToken();
|
String token = task.getResult().getToken();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
db.createUser(uid, token, name, email, picture);
|
if (!db.checkIfUserExists(FirebaseAuth.getInstance().getCurrentUser().getUid())) {
|
||||||
|
|
||||||
|
db.createUser(uid, token, name, picture, email);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
db.updateUser(uid, token, name, picture, email);
|
||||||
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Intent intent = new Intent(this, Dash.class);
|
Intent intent = new Intent(this, Dash.class);
|
||||||
|
@ -451,6 +451,17 @@ public class Database {
|
|||||||
sqlUpdate5Param(SQL, username, message_id, name, picture, email);
|
sqlUpdate5Param(SQL, username, message_id, name, picture, email);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Erstellt einen neuen User, wenn keiner existiert
|
||||||
|
*
|
||||||
|
* @param username Der Username des neuen Users
|
||||||
|
* @throws SQLException
|
||||||
|
*/
|
||||||
|
public void updateUser(String username, String message_id, String name, String picture, String email) throws SQLException {
|
||||||
|
String SQL = "Update \"User\" set message_id = ?, name = ?, picture = ?, email = ? WHERE username = ?";
|
||||||
|
sqlUpdate5Param(SQL, message_id, name, picture, email, username);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prüft ob ein User bereits in der DB vorhanden ist. Wenn ja dann wird true returned
|
* Prüft ob ein User bereits in der DB vorhanden ist. Wenn ja dann wird true returned
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user