Beispiel #1
0
        public AuthModule() : base("/auth")
        {
            StatelessAuthentication.Enable(this, KaiseiCore.StatelessConfig);

            //App
            Post("/sso", _ =>
            {
                if (Context.CurrentUser == null)
                {
                    return new Response
                    {
                        StatusCode = HttpStatusCode.Unauthorized
                    }
                }
                ;
                var sso    = this.Bind <SSOData>();
                var userId = ((UserModel)Context.CurrentUser).Id;
                return(KaiseiCore.AuthorizeApp(sso.AppId, userId));
            });


            Post(@"/", _ =>
            {
                var post = this.Bind <SSOData>();
                if (Context.CurrentUser != null)
                {
                    post.Verified = true;
                }
                return(View["Index", post]);
            });

            Post("/verifyPassword", _ =>
            {
                if (!(Context.CurrentUser is UserModel user))
                {
                    return new Response
                    {
                        StatusCode = HttpStatusCode.Unauthorized
                    }
                }
                ;
                var credentials = this.Bind <UserCredentials>();
                user            = KaiseiCore.VerifyUser(credentials);
                if (user == null)
                {
                    return new Response
                    {
                        StatusCode = HttpStatusCode.Unauthorized
                    }
                }
                ;
                else
                {
                    return new Response
                    {
                        StatusCode = HttpStatusCode.OK
                    }
                };
            });
Beispiel #2
0
 public AccountModule() : base("/account")
 {
     StatelessAuthentication.Enable(this, KaiseiCore.StatelessConfig);
     Get("/", _ =>
     {
         var user = (UserModel)Context.CurrentUser;
         if (user == null)
         {
             return(Response.AsRedirect("/"));
         }
         return(View["account", new
                     {
                         user.Username,
                         user.Email,
                         AuthedApps = new object[KaiseiCore.GetUserAuthedApps(user.Id).Length],
                         MyApps = new object[KaiseiCore.GetUserApps(user.Id).Length]
                     }]);
         //return $"{Context.Request.Headers.Referrer}"; //TODO: Create account page
     });
 }
Beispiel #3
0
 public LoginModule() : base("/login")
 {
     Post("/", _ =>
     {
         var user         = this.Bind <UserCredentials>();
         var verifiedUser = KaiseiCore.VerifyUser(user);
         if (verifiedUser == null)
         {
             return(new Response
             {
                 StatusCode = HttpStatusCode.Unauthorized
             });
         }
         else
         {
             return(new Response
             {
                 StatusCode = HttpStatusCode.OK,
             }.WithCookie("session", verifiedUser.Session));
         }
     });
     Post("/register", _ =>
     {
         var user           = this.Bind <UserCredentials>();
         var registeredUser = KaiseiCore.RegisterUser(user);
         if (registeredUser == null)
         {
             return(new Response
             {
                 StatusCode = HttpStatusCode.Unauthorized
             });
         }
         else
         {
             return(new Response
             {
                 StatusCode = HttpStatusCode.OK,
             }.WithCookie("session", registeredUser.Session));
         }
     });
 }
Beispiel #4
0
        public AppModule() : base("/app")
        {
            StatelessAuthentication.Enable(this, KaiseiCore.StatelessConfig);

            Get("/", _ => Context.CurrentUser);

            Get("/create", _ => {
                return(View["appCreate"]);
            });

            Get("/{id}", p =>
            {
                return(Response.AsJson(KaiseiCore.GetAppInfo(((string)p.id).Replace(' ', '+'))));
            });

            Get("/user/{id}", p =>
            {
                if (!(Context.CurrentUser is AppInfo app))
                {
                    return new Response
                    {
                        StatusCode = HttpStatusCode.Unauthorized
                    }
                }
                ;
                var apiKey  = ((AppInfo)Context.CurrentUser).ApiKey;
                var appUser = KaiseiCore.GetAppUser(apiKey, ((string)p.id).Replace(' ', '+'));
                if (appUser == null)
                {
                    return new Response {
                        StatusCode = HttpStatusCode.Unauthorized
                    }
                }
                ;
                else
                {
                    return(Response.AsJson(appUser));
                }
            });