Exemple #1
0
        public UserLoginResponse Login(string language, UserLoginRequest request)
        {
            string errorMessageKey = "";

            try
            {
                AppUser user = _work.LoadUserWithEmail(request.LoginName);
                if (user == null || request.Password != user.Password)
                {
                    errorMessageKey = ConstentMessages.UserNotExist;
                    throw new ArgumentException();
                }
                errorMessageKey = ConstentMessages.LoadRoleError;
                Dictionary <string, string> moduleRights = _work.LoadModuleRights(user.RoleId);

                DateTime utcNow = DateTime.UtcNow;
                user.Session = new AppSession {
                    Id = ObjectId.GenerateNewId().ToString(), CreateTs = utcNow, UpdateTs = utcNow
                };
                errorMessageKey = ConstentMessages.CreateSessionForUserError;
                _work.UpdateAppUser(user);
                return(new UserLoginResponse {
                    UserName = user.Name, SessionId = user.Session.Id, SessionUpdateTs = user.Session.UpdateTs.ToJsTime(), ModuleRights = moduleRights, SessionDuration = _appSetting.SessionDuration, UploadFileMaxSize = _appSetting.UploadFileMaxSize, UploadFileTypes = _appSetting.UploadFileTypes
                });
            }
            catch (Exception ex)
            {
                throw new TranslationException(_translator, language, errorMessageKey, ex);
            }
        }
Exemple #2
0
 protected ValidationResponse ValidateRight(AppUser user, string language, string appModuleName, List <string> rights)
 {
     if (user == null)
     {
         ValidationResponse response = new ValidationResponse();
         response.Messages.Add(_translator[language, ConstentMessages.UserNotExist]);
         return(response);
     }
     else
     {
         Dictionary <string, string> moduleRights = _baseUserWorkOfUnit.LoadModuleRights(user.RoleId);
         if (moduleRights.ContainsKey(appModuleName) && rights.Contains(moduleRights[appModuleName]))
         {
             return(null);
         }
         ValidationResponse response = new ValidationResponse();
         response.Messages.Add(_translator[language, ConstentMessages.UserHasNotRight]);
         return(response);
     }
 }