/// <summary>
		///		Произведение авторизации и всех сопутствующих процедур
		/// </summary>
		/// <param name="user">Пользователь</param>
		/// <param name="server">Сервер</param>
		/// <param name="context">Контекст</param>
		/// <returns>HandlerResult</returns>
		private HandlerResult ProcessUserLogin(IUser user, IHostServer server, WebContext context) {
			var identity = new Identity(user) {AuthenticationType = "secure"};
			context.User = new GenericPrincipal(identity, null);
			var logondata = new LogonInfo {
				Identity = identity,
				RemoteEndPoint = context.Request.RemoteEndPoint,
				LocalEndPoint = context.Request.LocalEndPoint,
				UserAgent = context.Request.UserAgent
			};
			var token = TokenService.Create(context.Request);
			TokenService.Store(context.Response, context.Request.Uri, token);
			return new HandlerResult { Result = true, Data = logondata };
		}
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="server"></param>
        /// <param name="context"></param>
        /// <param name="callbackEndPoint"></param>
        /// <param name="cancel"></param>
        /// <returns></returns>
        protected override HandlerResult GetResult(IHostServer server, WebContext context, string callbackEndPoint, CancellationToken cancel)
        {
            var ctx      = RequestParameters.Create(context);
            var login    = ctx.Get("login");
            var password = ctx.Get("pass");
            var identity = (Identity)LogonService.Logon(login, password);

            context.User = new GenericPrincipal(identity, null);
            var logondata = new LogonInfo {
                Identity       = identity,
                RemoteEndPoint = context.Request.RemoteEndPoint,
                LocalEndPoint  = context.Request.LocalEndPoint,
                UserAgent      = context.Request.UserAgent
            };
            var strRemoteIp = logondata.RemoteEndPoint.Address.ToString();

            if (identity.IsAuthenticated && !identity.IsGuest)
            {
                var token = TokenService.Create(context.Request);
                identity.User = identity.User ?? new User {
                    Login = identity.Name
                };
                var resolvedUsername = identity.User.Login;
                if (!string.IsNullOrWhiteSpace(identity.User.Domain))
                {
                    resolvedUsername = resolvedUsername + "@" + identity.User.Domain;
                }
                TokenService.Store(context.Response, context.Request.Uri, token);
                Loggy.Info("Login: "******", " + logondata.UserAgent + " from " + strRemoteIp);
                return(new HandlerResult {
                    Result = new{ auth = true, state = identity.State, stateinfo = identity.StateInfo }, Data = logondata
                });
            }
            if (!identity.IsAuthenticated && !identity.IsGuest)
            {
                Loggy.Warn("Login failed: " + context.User.Identity.Name + ", User Agent: [" + logondata.UserAgent + "] from ip: " + strRemoteIp);
            }
            TokenService.Store(context.Response, context.Request.Uri, null);
            return(new HandlerResult {
                Result = new { auth = false, state = identity.State, stateinfo = identity.StateInfo }, Data = logondata
            });
        }
        /// <summary>
        ///		Произведение авторизации и всех сопутствующих процедур
        /// </summary>
        /// <param name="user">Пользователь</param>
        /// <param name="server">Сервер</param>
        /// <param name="context">Контекст</param>
        /// <returns>HandlerResult</returns>
        private HandlerResult ProcessUserLogin(IUser user, IHostServer server, WebContext context)
        {
            var identity = new Identity(user)
            {
                AuthenticationType = "secure"
            };

            context.User = new GenericPrincipal(identity, null);
            var logondata = new LogonInfo {
                Identity       = identity,
                RemoteEndPoint = context.Request.RemoteEndPoint,
                LocalEndPoint  = context.Request.LocalEndPoint,
                UserAgent      = context.Request.UserAgent
            };
            var token = TokenService.Create(context.Request);

            TokenService.Store(context.Response, context.Request.Uri, token);
            return(new HandlerResult {
                Result = true, Data = logondata
            });
        }