public async Task <DinazorResult <TokenUser> > Login(BaseTokenUser user) { if (user == null) { var res = new DinazorResult <TokenUser>(); res.Status = ResultStatus.NoSuchObject; return(res); } //firstly check the user whether alredy logged in or not var alreadyLoggedInResult = IsUserAlreadyLoggedIn(user.Username, user.Password); if (!alreadyLoggedInResult.IsSuccess) { return(new DinazorResult <TokenUser>()); } if (alreadyLoggedInResult.Data) { _log.Info("user is already logged in"); //user already logged in. get the user return(GetUserByUsername(user.Username)); } // LICENCE CONTROL /* bool anyCommunicationProblem = false; * DinazorRestClient dinazorRestClient = new DinazorRestClient(); * DinazorResult<List<OrganizationLicenceDto>> licenceResult = new DinazorResult<List<OrganizationLicenceDto>>(); * try * { * licenceResult = await dinazorRestClient.Post(user.Client); * } * catch (Exception e) * { * _log.Error("licence manager communication problem",e); * anyCommunicationProblem = true; * licenceResult.Success(); * } * * if (!licenceResult.IsSuccess) * { * var licenceErrorResult = new DinazorResult<TokenUser> { Status = licenceResult.Status }; * return licenceErrorResult; * } * * //validate the licence * if (!anyCommunicationProblem && licenceResult.Data.Count <= 0) * { * var noLicenceResult = new DinazorResult<TokenUser> { Status = ResultStatus.NoLicence }; * return noLicenceResult; * }*/ if (true) { // try to login var result = await _authorizationOperation.Login(user); if (result.IsSuccess) { //generate the token var token = TokenGenerator.GenerateUniqueId(); //control the token if it already exists while (_tokenStorer.IsTokenExists(token).Status == ResultStatus.Success) { token = TokenGenerator.GenerateUniqueId(); } var tokenUser = result.Data; tokenUser.Token = token; //set the licence information tokenUser.Client = user.Client; tokenUser.IsLicenceValidated = true; // tokenUser.OrganizationLicence = licenceResult.Data; // get the roles according to licenced modules var userManager = IocManager.Instance.Resolve <IUserManager>(); var roleListResult = await userManager.GetUserByIdWithRoles(tokenUser.Id); if (roleListResult.IsSuccess) { tokenUser.RoleList = roleListResult.Data; } else { _log.Error("error while getting the role list"); } //store the user _tokenStorer.StoreTheToken(token, tokenUser); DinazorPrincipal.AuthenticateUser(token); LoginSubscriber.Broadcast(tokenUser); result.Data = tokenUser; return(result); } return(result); } /* else if (anyCommunicationProblem) * { * * }*/ return(null); }