Example #1
0
        public static async Task <HttpResponseMessage> Sign(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestMessage req,
            TraceWriter log)
        {
            log.Info("appDeveloper: Sign method started");
            var page       = InitPage(req);
            var accountBll = new AccountBll(new DatabaseHelper <Record>());

            var tokenClientId = req.GetQueryNameValuePairs().FirstOrDefault(q => q.Key == "In").Value;

            if (string.IsNullOrEmpty(tokenClientId) ||
                !Guid.TryParse(tokenClientId, out var _))
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, AValueIsInvalid));
            }

            //Check client permissions
            var userLogins = await accountBll.GetUserLogins(tokenClientId);

            if (!userLogins.Any())
            {
                return(page.RedirectResponse("Mistake"));
            }

            var returned = page.RedirectResponse("Index");

            returned.Headers.AddCookies(SetAuthCookie(req, tokenClientId, page.DebuggerIsAttached));
            return(returned);
        }
Example #2
0
        private static async Task <Login> GetClientLogin(HttpRequestMessage req, AccountBll accountBll)
        {
            var returned      = new Login();
            var tokenClientId = GetTokenClient(req);
            var userLogins    = await accountBll.GetUserLogins(tokenClientId);

            if (userLogins.Any())
            {
                returned.Client = userLogins.First();
            }
            returned.NotFound = !userLogins.Any() || string.IsNullOrEmpty(tokenClientId);

            return(returned);
        }