Liferay Login Screenlet - DXP

SCREENLETS IN LIFERAY SCREENS FOR ANDROID

Liferay Screens for Android contains several Screenlets that you can use in your Android apps. This section contains the reference documentation for each. If you’re looking for instructions on using Screens, see the Screens tutorials. The Screens tutorials contain instructions on using Screenlets and using views in Screenlets. Each Screenlet reference document here lists the Screenlet’s features, compatibility, its module (if any), available Views, attributes, listener methods, and more. The available Screenlets are listed here with links to their reference documents:

Let we go one by one Screenlet with example :

Login Screenlet: Signs users in to a Liferay instance.

The Login Screenlet authenticates portal users in your iOS app. The following authentication methods are supported:
  • Basic: uses user login and password according to HTTP Basic Access Authentication specification. Depending on the authentication method used by your Liferay instance, you need to provide the user’s email address, screen name, or user ID. You also need to provide the user’s password.
  • OAuth: implements the OAuth 1.0a specification.
  • Cookie: uses a cookie to log in. This lets you access documents and images in the portal’s document library without the guest view permission in the portal. The other authentication types require this permission to access such files.
When a user successfully authenticates, their attributes are retrieved for use in the app. You can use the SessionContext class to get the current user’s attributes.
Note that user credentials and attributes can be stored securely in the keychain (see the saveCredentialsattribute). Stored user credentials can be used to automatically log the user in to subsequent sessions. To do this, you can use the method SessionContext.loadStoredCredentials() method.screens-ios-login.png
1.Create new project-projectname-empty screenlet.
2.In build.gradle(Module)
add Liferay implementation code:
    implementation 'com.liferay.mobile:liferay-screens:+'
    implementation 'com.liferay.mobile:liferay-material-viewset:+'
    implementation 'com.liferay.mobile:liferay-westeros-viewset:+'

such as 

Now refersh by clicking "Sync-now",

For few will get error such as change the minSdkVersion 15 to 16.
In that case just change minSdkVersion 16.

2. Very important step where you need to configure liferay server .
create a new xml "server-context.xml" inside res/value/server-context.xml
copy paste below code:

<?xml version="1.0" encoding="utf-8"?><resources>

!-- Change these values for your Liferay Portal installation -->
    <string name="liferay_server">http://ip-address:port no</string>
     Ex: http://10.0.2.2:8080
    <integer name="liferay_company_id">companyid</integer>
    <integer name="liferay_group_id">groupid</integer>
    <integer name="liferay_portal_version">70</integer>
</resources>

3.Modify the "activity-main.xml" inside res/layout/activity-main.xml

add the below entry

 xmlns:liferay="http://schemas.android.com/apk/res-auto"


<com.liferay.mobile.screens.auth.login.LoginScreenlet
android:id="@+id/login_screenlet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
liferay:basicAuthMethod="email"
liferay:credentialsStorage="auto"
liferay:layoutId="@layout/login_material"/>



Layout Id can be provided with 3 options :
@layout/login_material
@layout/login_westeros
@layout/login_default


Now Go to controller & add below lines
1. public class MainActivity extends AppCompatActivity implements LoginListener

2.
public class MainActivity extends AppCompatActivity implements LoginListener {

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        LoginScreenlet loginScreenlet = (LoginScreenlet) findViewById(R.id.login_screenlet);

        loginScreenlet.setListener(this);
    }

    @Override    public void onLoginSuccess(User user) {
    System.out.print(user.getEmail() + " "+ user.getScreenName() + " " + user.getValues());
        startActivity(new Intent(MainActivity.this, ActivityOne.class));
    }

    @Override    public void onLoginFailure(Exception e) {

        Toast.makeText(MainActivity.this, "Login failed!", Toast.LENGTH_SHORT).show();
    }

    @Override    public void onAuthenticationBrowserShown() {

    }
}

3.Create one new Activity with the name "ActivityOne", so that once you login that page will redirects 
  ActivityOne controller.


we used loginScreenlet inside onCreate method
      LoginScreenlet loginScreenlet = (LoginScreenlet) findViewById(R.id.login_screenlet);
      loginScreenlet.setListener(this);


OnLoginSuccess method calls startActivity if it finds MainActivity, then 
it will transfer controller to ActivityOne.

onLoginFailure method just print faled login message.



Now just run a simulator, you can find mobile view 



Try to login with Incorrect email & password, It should through failed message !!

Now login with Correct email & password, Login Success ! Happens, & Redirect to Empty Page.



In next blog, Will do DDL form using screenlets.


Comments

Popular posts from this blog

AUI Form In LifeRay

LifeRay 7 with Single Page Application (SPA) features & SennaJs !!! How It works? In LR7 & LR6.2..

Hide Default Liferay Error Message in login.jsp (HOOK)