Example #1
0
 private void LogResult(IIdentity result, string opid)
 {
     if (!result.IsAuthenticated)
     {
         if (Logg.IsForWarn())
         {
             Logg.Warn(new { logonid = opid, auth = false, result }.stringify());
         }
     }
     else
     {
         if (Logg.IsForInfo())
         {
             Logg.Info(new { logonid = opid, auth = true, result }.stringify());
         }
     }
 }
Example #2
0
        private UpdateResult UpdateResult(IIdentity actor, IUser target, bool store, UserUpdateInfo updateinfo
                                          )
        {
            UpdateResult res = null;

            Logg.Info(new { updateusr = "******", usr = actor.Name, info = updateinfo }.stringify());
            if (string.IsNullOrWhiteSpace(updateinfo.Login))
            {
                updateinfo.Login = actor.Name;
            }
            target = target ?? Users.GetUser(updateinfo.Login);
            var newuser = target == null;

            if (!updateinfo.HasDelta(target))
            {
                return(new UpdateResult {
                    Ok = true, Message = "notchanged", ResultUser = target
                });
            }

            res = Checker.ValidateUpdate(actor, updateinfo, target);
            if (!res.Ok)
            {
                Logg.Warn(
                    new { updateusr = "******", validation = res, usr = actor.Name, info = updateinfo }.stringify());

                return(res);
            }
            if (null == target)
            {
                target = new User {
                    Login = updateinfo.Login
                };
            }
            updateinfo.Apply(target);
            UserPolicy policy = null;

            if (newuser)
            {
                policy = UserPolicy.GetNewUserPolicy(updateinfo);
            }
            if (null != policy)
            {
                policy.Apply(target);
            }
            if (store)
            {
                Users.Store(target);
            }
            if (null != policy && policy.MakePassRequest && null != Messendger)
            {
                if (newuser)
                {
                    Messendger.SendWelcome(target);
                }
            }
            Logg.Info(new { updateusr = "******", result = target, usr = actor.Name, info = updateinfo }.stringify());
            Users.Clear();
            Roles.Clear();
            res = new UpdateResult {
                Ok = true, ResultUser = target
            };
            return(res);
        }