Search in sources :

Example 1 with EzyLoginParams

use of com.tvd12.ezyfoxserver.response.EzyLoginParams in project ezyfox-server by youngmonkeys.

the class EzyLoginControllerTest method testSetUserProperties.

@Test
public void testSetUserProperties() {
    EzySimpleServerContext ctx = (EzySimpleServerContext) newServerContext();
    EzySimpleServer server = (EzySimpleServer) ctx.getServer();
    server.setResponseApi(mock(EzyResponseApi.class));
    EzySession session = newSession();
    session.setToken("abcdef");
    EzyArray data = newLoginData();
    EzySimpleLoginRequest request = new EzySimpleLoginRequest();
    request.deserializeParams(data);
    request.setSession(session);
    EzyLoginProcessor processor = new EzyLoginProcessor(ctx);
    EzyZoneContext zoneContext = ctx.getZoneContext("example");
    EzyLoginParams params = request.getParams();
    EzySimpleUserLoginEvent event = new EzySimpleUserLoginEvent(session, params.getZoneName(), params.getUsername(), params.getPassword(), params.getData());
    event.setUserProperty("dataId", 123L);
    processor.apply(zoneContext, event);
    event.release();
    EzyZoneUserManager userManager = zoneContext.getZone().getUserManager();
    EzyUser user = userManager.getUser("dungtv");
    assert user.getProperty("dataId").equals(123L);
}
Also used : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzySimpleUserLoginEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserLoginEvent) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyLoginParams(com.tvd12.ezyfoxserver.request.EzyLoginParams) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySimpleLoginRequest(com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyLoginProcessor(com.tvd12.ezyfoxserver.controller.EzyLoginProcessor) EzyZoneUserManager(com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager) Test(org.testng.annotations.Test)

Example 2 with EzyLoginParams

use of com.tvd12.ezyfoxserver.response.EzyLoginParams in project ezyfox-server by youngmonkeys.

the class EzyLoginResponseTest method test.

@Test
public void test() {
    EzyArray data = EzyEntityFactory.EMPTY_ARRAY;
    EzyLoginParams params = new EzyLoginParams();
    params.setZoneId(1);
    params.setZoneName("test");
    params.setUserId(2);
    params.setData(data);
    params.setUsername("name");
    assert params.getZoneId() == 1;
    assert params.getZoneName().equals("test");
    assert params.getUserId() == 2;
    assert params.getData() == data;
    assert params.getUsername().equals("name");
    EzyLoginResponse response = new EzyLoginResponse(params);
    assert response.getParams() == params;
    response.release();
}
Also used : EzyLoginParams(com.tvd12.ezyfoxserver.response.EzyLoginParams) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzyLoginResponse(com.tvd12.ezyfoxserver.response.EzyLoginResponse) BaseTest(com.tvd12.test.base.BaseTest) Test(org.testng.annotations.Test)

Example 3 with EzyLoginParams

use of com.tvd12.ezyfoxserver.response.EzyLoginParams in project ezyfox-server by youngmonkeys.

the class EzyLoginController method handle.

@Override
public void handle(EzyServerContext ctx, EzyLoginRequest request) {
    try {
        EzySession session = request.getSession();
        EzyLoginParams params = request.getParams();
        EzyZoneContext zoneContext = ctx.getZoneContext(params.getZoneName());
        EzyUserLoginEvent loginEvent = newLoginEvent(session, params);
        try {
            control(ctx, zoneContext, loginEvent);
        } finally {
            loginEvent.release();
        }
    } catch (EzyLoginErrorException e) {
        processException(ctx, request.getSession(), e);
        throw e;
    } catch (EzyMaxUserException e) {
        processException(ctx, request.getSession(), maximumUsers(e));
        throw e;
    } catch (EzyZoneNotFoundException e) {
        processException(ctx, request.getSession(), zoneNotFound(e));
        throw e;
    } catch (Exception e) {
        processException(ctx, request.getSession(), serverError(e));
        throw e;
    }
}
Also used : EzyMaxUserException(com.tvd12.ezyfoxserver.exception.EzyMaxUserException) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyZoneNotFoundException(com.tvd12.ezyfoxserver.exception.EzyZoneNotFoundException) EzyLoginParams(com.tvd12.ezyfoxserver.request.EzyLoginParams) EzyLoginErrorException(com.tvd12.ezyfoxserver.exception.EzyLoginErrorException) EzyUserLoginEvent(com.tvd12.ezyfoxserver.event.EzyUserLoginEvent) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyLoginErrorException(com.tvd12.ezyfoxserver.exception.EzyLoginErrorException) EzyMaxUserException(com.tvd12.ezyfoxserver.exception.EzyMaxUserException) EzyZoneNotFoundException(com.tvd12.ezyfoxserver.exception.EzyZoneNotFoundException)

Example 4 with EzyLoginParams

use of com.tvd12.ezyfoxserver.response.EzyLoginParams in project ezyfox-server by youngmonkeys.

the class EzyLoginProcessor method newLoginResponse.

protected EzyResponse newLoginResponse(EzyZoneContext zoneContext, EzyUser user, EzyData loginOutputData) {
    EzyZoneSetting zoneSetting = getZoneSetting(zoneContext);
    EzyLoginParams params = new EzyLoginParams();
    params.setData(loginOutputData);
    params.setUserId(user.getId());
    params.setUsername(user.getName());
    params.setZoneId(zoneSetting.getId());
    params.setZoneName(zoneSetting.getName());
    return new EzyLoginResponse(params);
}
Also used : EzyZoneSetting(com.tvd12.ezyfoxserver.setting.EzyZoneSetting) EzyLoginParams(com.tvd12.ezyfoxserver.response.EzyLoginParams) EzyLoginResponse(com.tvd12.ezyfoxserver.response.EzyLoginResponse)

Aggregations

EzyArray (com.tvd12.ezyfox.entity.EzyArray)2 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)2 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)2 EzyLoginParams (com.tvd12.ezyfoxserver.request.EzyLoginParams)2 EzyLoginParams (com.tvd12.ezyfoxserver.response.EzyLoginParams)2 EzyLoginResponse (com.tvd12.ezyfoxserver.response.EzyLoginResponse)2 Test (org.testng.annotations.Test)2 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)1 EzyResponseApi (com.tvd12.ezyfoxserver.api.EzyResponseApi)1 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)1 EzyLoginProcessor (com.tvd12.ezyfoxserver.controller.EzyLoginProcessor)1 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)1 EzySimpleUserLoginEvent (com.tvd12.ezyfoxserver.event.EzySimpleUserLoginEvent)1 EzyUserLoginEvent (com.tvd12.ezyfoxserver.event.EzyUserLoginEvent)1 EzyLoginErrorException (com.tvd12.ezyfoxserver.exception.EzyLoginErrorException)1 EzyMaxUserException (com.tvd12.ezyfoxserver.exception.EzyMaxUserException)1 EzyZoneNotFoundException (com.tvd12.ezyfoxserver.exception.EzyZoneNotFoundException)1 EzySimpleLoginRequest (com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest)1 EzyZoneSetting (com.tvd12.ezyfoxserver.setting.EzyZoneSetting)1 EzyZoneUserManager (com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager)1