@@ -583,6 +583,8 @@ func isUserEnabled(apiKey string, args []string) func(*sql.DB) {
583
583
func loginUserWithUsername (apiKey string , args []string ) func (* sql.DB ) {
584
584
username := args [2 ]
585
585
password := args [3 ]
586
+ useragent := args [4 ]
587
+ address := args [5 ]
586
588
587
589
if ! validateUsername (username ) {
588
590
proc .ShowFailedResponse ("Invalid username string." )
@@ -610,13 +612,14 @@ func loginUserWithUsername(apiKey string, args []string) func(*sql.DB) {
610
612
}
611
613
612
614
if count != 1 {
613
- proc .ShowResult ("\" error \" " )
615
+ proc .ShowResult ("\" 0 \" " )
614
616
}
615
617
616
618
uuid := uuid .New ().String ()
617
619
query , err = d .Query ("INSERT INTO " + apiKey +
618
- "_account_session (username, uuid) VALUES(\" " +
619
- username + "\" , \" " + uuid + "\" )" )
620
+ "_account_session (username, uuid, useragent, address) VALUES(\" " +
621
+ username + "\" , \" " + uuid + "\" , \" " +
622
+ useragent + "\" , \" " + address + "\" )" )
620
623
621
624
if err != nil {
622
625
proc .ShowFailedResponse ("Internal error occured." )
@@ -631,6 +634,8 @@ func loginUserWithUsername(apiKey string, args []string) func(*sql.DB) {
631
634
func loginUserWithEmail (apiKey string , args []string ) func (* sql.DB ) {
632
635
email := args [2 ]
633
636
password := args [3 ]
637
+ useragent := args [4 ]
638
+ address := args [5 ]
634
639
635
640
if ! validateEmail (email ) {
636
641
proc .ShowFailedResponse ("Invalid email string." )
@@ -643,7 +648,7 @@ func loginUserWithEmail(apiKey string, args []string) func(*sql.DB) {
643
648
}
644
649
645
650
return func (d * sql.DB ) {
646
- query , err := d .Query ("SELECT * FROM " + apiKey +
651
+ query , err := d .Query ("SELECT username FROM " + apiKey +
647
652
"_accounts WHERE email=\" " + email +
648
653
"\" AND password=\" " + password + "\" " )
649
654
@@ -652,17 +657,29 @@ func loginUserWithEmail(apiKey string, args []string) func(*sql.DB) {
652
657
return
653
658
}
654
659
660
+ username := ""
655
661
count := 0
656
662
for query .Next () {
663
+ query .Scan (& username )
657
664
count += 1
658
665
}
659
666
660
- if count == 1 {
661
- proc .ShowResult ("\" 1\" " )
662
- } else {
667
+ if count != 1 {
663
668
proc .ShowResult ("\" 0\" " )
664
669
}
665
670
671
+ uuid := uuid .New ().String ()
672
+ query , err = d .Query ("INSERT INTO " + apiKey +
673
+ "_account_session (username, uuid, useragent, address) VALUES(\" " +
674
+ username + "\" , \" " + uuid + "\" , \" " +
675
+ useragent + "\" , \" " + address + "\" )" )
676
+
677
+ if err != nil {
678
+ proc .ShowFailedResponse ("Internal error occured." )
679
+ return
680
+ }
681
+
682
+ proc .ShowResult ("\" " + uuid + "\" " )
666
683
query .Close ()
667
684
}
668
685
}
0 commit comments