Search in sources :

Example 1 with BackendUser

use of io.divide.client.BackendUser in project divide by HiddenStage.

the class AuthManagerTest method testGetRemoteUserFromToken.

@Test
public void testGetRemoteUserFromToken() throws Exception {
    SignUpResponse response = authManager.signUp(new SignUpCredentials("name", "email", ""));
    BackendUser user = response.get();
    assertEquals(user.getUsername(), "name");
    BackendUser credentials = authManager.getUserFromAuthToken(user.getAuthToken()).toBlockingObservable().first();
    assertEquals(credentials.getUsername(), "name");
}
Also used : SignUpCredentials(io.divide.client.auth.credentials.SignUpCredentials) BackendUser(io.divide.client.BackendUser) ClientTest(io.divide.client.ClientTest) Test(org.junit.Test)

Example 2 with BackendUser

use of io.divide.client.BackendUser in project divide by HiddenStage.

the class AuthManagerTest method testLogin.

@Test
public void testLogin() throws Exception {
    SignUpCredentials signUpCredentials = new SignUpCredentials("name", "email", "");
    String unEncryptedPW = signUpCredentials.getPassword();
    BackendUser signInUser = authManager.signUp(signUpCredentials).get();
    BackendUser user = authManager.login(new LoginCredentials(signInUser.getEmailAddress(), unEncryptedPW)).get();
    assertNotNull(user);
    assertEquals(signInUser.getUsername(), user.getUsername());
}
Also used : LoginCredentials(io.divide.client.auth.credentials.LoginCredentials) SignUpCredentials(io.divide.client.auth.credentials.SignUpCredentials) BackendUser(io.divide.client.BackendUser) ClientTest(io.divide.client.ClientTest) Test(org.junit.Test)

Example 3 with BackendUser

use of io.divide.client.BackendUser in project divide by HiddenStage.

the class DebugAuthActivity method onCreate.

/**
     * Called when the activity is first created.
     */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String title = this.getIntent().getStringExtra(TITLE_EXTRA);
    if (title == null)
        title = getApplicationName(this);
    CredentialView credentialView = new CredentialView(this, title);
    DivideDrawer.attach(this, credentialView);
    BackendServices.addLoginListener(new LoginListener() {

        @Override
        public void onNext(BackendUser backendUser) {
            if (backendUser != null) {
                DebugAuthActivity.this.finish();
            }
        }
    });
    this.closeOptionsMenu();
}
Also used : LoginListener(io.divide.client.auth.LoginListener) CredentialView(io.divide.client.android.CredentialView) BackendUser(io.divide.client.BackendUser)

Example 4 with BackendUser

use of io.divide.client.BackendUser in project divide by HiddenStage.

the class MyActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    DivideDrawer.attach(this, R.layout.main);
    //        setContentView(R.layout.main);
    ButterKnife.inject(this);
    getActionBar().setHomeButtonEnabled(true);
    //        au = AuthUtils.get(this, AuthManager.ACCOUNT_TYPE); TODO replace this
    app = (MyApplication) this.getApplication();
    BackendServices.addLoginListener(new LoginListener() {

        @Override
        public void onNext(BackendUser user) {
            System.out.println("loginListener: setUser: " + user);
            if (user != null) {
                setUser(user);
            }
        }
    });
    adapter = new BackendObjectAdaper(this, objectList);
    usersLV.setAdapter(adapter);
    usersLV.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            BackendObject o = adapter.getItem(position);
            Query q = new QueryBuilder().delete().from(BackendObject.class).where(TransientObject.OBJECT_KEY, OPERAND.EQ, o.getObjectKey()).build();
            BackendServices.remote().query(BackendObject.class, q).subscribe(new Action1<Collection<BackendObject>>() {

                @Override
                public void call(Collection<BackendObject> backendObjects) {
                    getObjects();
                }
            });
            BackendServices.local().delete(o);
        }
    });
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            if (BackendUser.isLoggedIn())
                getObjects();
            else
                logger.debug("Not signed in, not querying data.");
        }
    }, 1000);
    Storage s = new XmlStorage(new File(this.getFilesDir() + File.separator + "something.xml"), Storage.MODE_WORLD_WRITEABLE);
    String id = "something";
    System.out.println("Stored: " + s.getString(id, ""));
    System.out.println("Stored: " + s.contains(id));
    s.edit().putString(id, "something2").commit();
    s.edit().putInt("int", 55).commit();
}
Also used : BackendObject(io.divide.client.BackendObject) Action1(rx.functions.Action1) Query(io.divide.shared.transitory.query.Query) Handler(android.os.Handler) QueryBuilder(io.divide.shared.transitory.query.QueryBuilder) BackendUser(io.divide.client.BackendUser) InjectView(butterknife.InjectView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) XmlStorage(io.divide.shared.file.XmlStorage) LoginListener(io.divide.client.auth.LoginListener) Storage(io.divide.shared.file.Storage) XmlStorage(io.divide.shared.file.XmlStorage) Collection(java.util.Collection) AdapterView(android.widget.AdapterView) File(java.io.File)

Example 5 with BackendUser

use of io.divide.client.BackendUser in project divide by HiddenStage.

the class AuthActivity method onCreate.

/**
     * Called when the activity is first created.
     */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String title = this.getIntent().getStringExtra(EXTRA_TITLE);
    if (title == null)
        title = getApplicationName(this);
    boolean enableAnonymous = this.getIntent().getBooleanExtra(EXTRA_ENABLE_ANONYMOUS_LOGIN, false);
    CredentialView credentialView = new CredentialView(this, title);
    if (enableAnonymous)
        credentialView.enableAnonymousLogin();
    setContentView(credentialView);
    BackendServices.addLoginListener(new LoginListener() {

        @Override
        public void onNext(BackendUser backendUser) {
            if (backendUser != null) {
                AuthActivity.this.finish();
            }
        }
    });
    this.closeOptionsMenu();
}
Also used : LoginListener(io.divide.client.auth.LoginListener) BackendUser(io.divide.client.BackendUser)

Aggregations

BackendUser (io.divide.client.BackendUser)11 ClientTest (io.divide.client.ClientTest)6 SignUpCredentials (io.divide.client.auth.credentials.SignUpCredentials)6 Test (org.junit.Test)6 LoginListener (io.divide.client.auth.LoginListener)3 LoginCredentials (io.divide.client.auth.credentials.LoginCredentials)3 ValidCredentials (io.divide.client.auth.credentials.ValidCredentials)2 PublicKey (java.security.PublicKey)2 Handler (android.os.Handler)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 InjectView (butterknife.InjectView)1 BackendObject (io.divide.client.BackendObject)1 CredentialView (io.divide.client.android.CredentialView)1 Storage (io.divide.shared.file.Storage)1 XmlStorage (io.divide.shared.file.XmlStorage)1 Query (io.divide.shared.transitory.query.Query)1 QueryBuilder (io.divide.shared.transitory.query.QueryBuilder)1