File tree Expand file tree Collapse file tree 2 files changed +54
-4
lines changed
Expand file tree Collapse file tree 2 files changed +54
-4
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace ProcessWire \GraphQL \Field \Auth ;
4+
5+ use Youshido \GraphQL \Field \AbstractField ;
6+ use Youshido \GraphQL \Config \Field \FieldConfig ;
7+ use Youshido \GraphQL \Type \Scalar \StringType ;
8+ use Youshido \GraphQL \Type \NonNullType ;
9+ use Youshido \GraphQL \Execution \ResolveInfo ;
10+
11+ class LoginField extends AbstractField {
12+
13+ public function getType ()
14+ {
15+ return new StringType ();
16+ }
17+
18+ public function getName ()
19+ {
20+ return 'login ' ;
21+ }
22+
23+ public function getDescription ()
24+ {
25+ return 'Allows you to authenticate into the app. ' ;
26+ }
27+
28+ public function build (FieldConfig $ config )
29+ {
30+ $ config ->addArgument ('username ' , new NonNullType (new StringType ()));
31+ $ config ->addArgument ('password ' , new NonNullType (new StringType ()));
32+ }
33+
34+ public function resolve ($ value , array $ args , ResolveInfo $ info )
35+ {
36+ $ session = \ProcessWire \wire ('session ' );
37+ $ username = $ args ['username ' ];
38+ $ password = $ args ['password ' ];
39+ $ user = $ session ->login ($ username , $ password );
40+ if (is_null ($ user )) {
41+ return 'Failed to login ' ;
42+ } else {
43+ return 'Login successful ' ;
44+ }
45+ }
46+
47+ }
Original file line number Diff line number Diff line change 22
33use Youshido \GraphQL \Config \Schema \SchemaConfig ;
44use Youshido \GraphQL \Schema \AbstractSchema ;
5+ use ProcessWire \GraphQL \Settings ;
56use ProcessWire \GraphQL \Field \Pages \PagesField ;
67use ProcessWire \GraphQL \Field \TemplatedPageArray \TemplatedPageArrayField ;
78use ProcessWire \GraphQL \Field \Debug \DbQueryCountField ;
8- use ProcessWire \GraphQL \Settings ;
9+ use ProcessWire \GraphQL \Field \Auth \LoginField ;
10+
911
1012
1113class Schema extends AbstractSchema {
@@ -26,10 +28,11 @@ public function build(SchemaConfig $config)
2628
2729 // Debugging
2830 if (Settings::module ()->debug ) {
29- $ query ->addFields ([
30- new DbQueryCountField ()
31- ]);
31+ $ query ->addField (new DbQueryCountField ());
3232 }
33+
34+ // Auth
35+ $ query ->addfield (new LoginField ());
3336 }
3437
3538 public function getName ()
You can’t perform that action at this time.
0 commit comments