@@ -39,6 +39,8 @@ func CreateUser(ctx echo.Context) error {
3939 })
4040 }
4141
42+ payload .Email = strings .ToLower (payload .Email )
43+
4244 _ , err := services .FindUserByEmail (payload .Email )
4345 if err != nil && ! errors .Is (err , sql .ErrNoRows ) {
4446 return ctx .JSON (http .StatusInternalServerError , map [string ]string {
@@ -259,10 +261,10 @@ func CompleteProfile(ctx echo.Context) error {
259261 })
260262 }
261263
262- // err = services.WriteUserToGoogleSheet(* user)
263- // if err != nil {
264- // slog.Error(err.Error())
265- // }
264+ err = services .WriteUserToGoogleSheet (user . User )
265+ if err != nil {
266+ slog .Error (err .Error ())
267+ }
266268
267269 return ctx .JSON (http .StatusOK , map [string ]string {
268270 "message" : "user profile updated" ,
@@ -322,6 +324,19 @@ func UpdateUser(ctx echo.Context) error {
322324 })
323325 }
324326
327+ payload .FirstName = strings .TrimSpace (payload .FirstName )
328+ payload .LastName = strings .TrimSpace (payload .LastName )
329+ payload .PhoneNumber = strings .TrimSpace (payload .PhoneNumber )
330+ payload .Gender = strings .TrimSpace (payload .Gender )
331+ payload .VitEmail = strings .TrimSpace (payload .VitEmail )
332+ payload .HostelBlock = strings .TrimSpace (payload .HostelBlock )
333+ payload .College = strings .TrimSpace (payload .College )
334+ payload .City = strings .TrimSpace (payload .City )
335+ payload .State = strings .TrimSpace (payload .State )
336+ payload .Country = strings .TrimSpace (payload .Country )
337+ payload .RegNo = strings .TrimSpace (payload .RegNo )
338+ payload .Room = strings .TrimSpace (payload .Room )
339+
325340 if payload .FirstName != "" {
326341 user .FirstName = payload .FirstName
327342 }
@@ -334,27 +349,15 @@ func UpdateUser(ctx echo.Context) error {
334349 if payload .Gender != "" {
335350 user .Gender = payload .Gender
336351 }
337- if payload .VitEmail != "" {
338- user .VITDetails .Email = payload .VitEmail
339- }
340352 if payload .HostelBlock != "" {
341353 user .Block = payload .HostelBlock
342354 }
343- if payload .College != "" {
344- user .College = payload .College
345- }
346- if payload .City != "" {
347- user .City = payload .City
348- }
349- if payload .State != "" {
350- user .State = payload .State
351- }
352- if payload .Country != "" {
353- user .Country = payload .Country
354- }
355355 if payload .RegNo != "" {
356356 user .RegNo = payload .RegNo
357357 }
358+ if payload .Room != "" {
359+ user .Room = payload .Room
360+ }
358361
359362 if err := services .UpdateUser (& user .User ); err != nil {
360363 var pgerr * pgconn.PgError
@@ -455,6 +458,8 @@ func VerifyUser(ctx echo.Context) error {
455458 })
456459 }
457460
461+ database .RedisClient .Delete ("verification:" + user .User .Email )
462+
458463 return ctx .JSON (http .StatusOK , map [string ]string {
459464 "message" : "User verified" ,
460465 "status" : "success" ,
@@ -579,7 +584,7 @@ func RequestResetPassword(ctx echo.Context) error {
579584 })
580585 }
581586
582- if err := database .RedisClient .Set ("resettries" + payload .Email , fmt .Sprint (1 ), time .Minute * 5 ); err != nil {
587+ if err := database .RedisClient .Set ("resettries: " + payload .Email , fmt .Sprint (1 ), time .Minute * 5 ); err != nil {
583588 return ctx .JSON (http .StatusInternalServerError , map [string ]string {
584589 "message" : err .Error (),
585590 "status" : "error" ,
@@ -636,7 +641,7 @@ func ResetPassword(ctx echo.Context) error {
636641 })
637642 }
638643
639- triesString , err := database .RedisClient .Get ("resettries" + payload .Email )
644+ triesString , err := database .RedisClient .Get ("resettries: " + payload .Email )
640645 if err != nil {
641646 if err == redis .Nil {
642647 return ctx .JSON (http .StatusForbidden , map [string ]string {
@@ -653,7 +658,7 @@ func ResetPassword(ctx echo.Context) error {
653658 tries , _ := strconv .Atoi (triesString )
654659
655660 if tries >= 10 {
656- database .RedisClient .Delete ("resetpass" + payload .Email )
661+ database .RedisClient .Delete ("resetpass: " + payload .Email )
657662 return ctx .JSON (http .StatusGone , map [string ]string {
658663 "message" : "otp expired" ,
659664 "status" : "fail" ,
@@ -675,7 +680,7 @@ func ResetPassword(ctx echo.Context) error {
675680 }
676681
677682 if payload .OTP != otp {
678- if err := database .RedisClient .Set ("resettries" + payload .Email , fmt .Sprint (tries + 1 ), time .Minute * 5 ); err != nil {
683+ if err := database .RedisClient .Set ("resettries: " + payload .Email , fmt .Sprint (tries + 1 ), time .Minute * 5 ); err != nil {
679684 return ctx .JSON (http .StatusInternalServerError , map [string ]string {
680685 "message" : err .Error (),
681686 "status" : "error" ,
@@ -695,7 +700,7 @@ func ResetPassword(ctx echo.Context) error {
695700 })
696701 }
697702
698- err = services .ResetPassword (payload . Email , string (hashed ))
703+ err = services .ResetPassword (string (hashed ), payload . Email )
699704 if err != nil {
700705 if errors .Is (err , sql .ErrNoRows ) {
701706 return ctx .JSON (http .StatusNotFound , map [string ]string {
@@ -709,6 +714,8 @@ func ResetPassword(ctx echo.Context) error {
709714 })
710715 }
711716
717+ database .RedisClient .Delete ("resetpass:" + payload .Email )
718+
712719 return ctx .JSON (http .StatusOK , map [string ]string {
713720 "status" : "success" ,
714721 "message" : "password reset successfully" ,
0 commit comments