Usage

How to register a new user?

There are several ways to add a user to JFW, you can choose which way to implement the register method that suits your needs.

Notes: JFW doesn't try to mutate your inputs. The instance you create is for providing the required data to add a new user. If you want to get the newly created user, you have to use methods to get the one you want.

  1. Create a new instance, then assign field values, then use CUser.Add to add the instance to the database. (This way will return the newly created instance).

var aNewUser = new CUser
{
    BrandId = 1,
    Username = "admin"
    Password = "@Abc123456",
    UserType = (short)UserType.EndUser,
    Status = 1
};
var aNewCreatedUser = CUser.Add(aNewUser);
  1. Create a new instance, then assign field values, then use CUser.RegisterUser to add the instance to the database. (This way will return the registration status not the newly created instance, you can retrieve the newly created instance by adding out parameter if necessary).

using Jfw.Core.Enums;
using Jfw.Core.EntityClasses;

var aNewUser = new CUser

{
    BrandId = 1,
    Username = "admin"
    Password = "@Abc123456",
    UserType = (short)UserType.EndUser,
    Status = 1
};
CUser outputUser;
var status = CUser.RegisterUser(aNewUser, out outputUser);
  1. You can fill in pre-defined parameters in CUser.RegisterUser.

string brandUrl = "https://jfwlab.com";
string username = "admin";
string password = "@Abc123456";
string email = "[email protected]";
CUser outputUser;
var status = CUser.RegisterUser(brandUrl, username, password, email, out outputUser);

How to log in as a user?

Notes: Adding a User instance to your Session Manager when calling CUser.LoginWith__ is not supported. You have to add the instance manually by using CSessionManager or your own Session Manager.

To log in as a user, you have to call CUser.LoginWith__, then it will return the login status for the data you provided. If the status is LoginStatus.Success, you can get the user instance by providing an output parameter. Then you can use the user instance to do other things like set the session, etc.

Get the login status by calling CUser.LoginWith__.

string brandUrl = "https://jfwlab.com";
string username = "admin";
string password = "@Abc123456";
CUser aValidUser;
var loginStatus = CUser.LoginWithUsername(brandUrl, username, password, out aValidUser);

Use the user instance to do other things like set the session, etc. In this example, we will use an example from CSessionManager.

SessionManager.CurrentUser = aValidUser;

Last updated

Was this helpful?