Update user on startup
This commit is contained in:
		@@ -74,7 +74,7 @@ public class LoginActivity extends AppCompatActivity {
 | 
			
		||||
     * Wechselt zu der Dash Activity
 | 
			
		||||
     */
 | 
			
		||||
    private void goDash() {
 | 
			
		||||
            if (!db.checkIfUserExists(FirebaseAuth.getInstance().getCurrentUser().getUid())) {
 | 
			
		||||
 | 
			
		||||
        FirebaseInstanceId.getInstance().getInstanceId()
 | 
			
		||||
                .addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
 | 
			
		||||
                    @Override
 | 
			
		||||
@@ -92,14 +92,21 @@ public class LoginActivity extends AppCompatActivity {
 | 
			
		||||
 | 
			
		||||
                        // Get new Instance ID token
 | 
			
		||||
                        String token = task.getResult().getToken();
 | 
			
		||||
 | 
			
		||||
                        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) {
 | 
			
		||||
                            e.printStackTrace();
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                    }
 | 
			
		||||
                });
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        Intent intent = new Intent(this, Dash.class);
 | 
			
		||||
 
 | 
			
		||||
@@ -451,6 +451,17 @@ public class Database {
 | 
			
		||||
        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
 | 
			
		||||
     *
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user