public IActionResult Verify([FromBody] Verification verify)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest());
     }
     else
     {
         UidwithMessage ans = repo.VerifyKey(verify);
         if (ans.Message.Equals("True"))
         {
             return(Ok(ans));
         }
         else
         {
             return(BadRequest());
         }
     }
 }
        public IActionResult Register([FromBody] Register register)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            else
            {
                if (register.UserName.Length > 25)
                {
                    return(BadRequest());
                }

                else if ((register.Password.Length > 15) || (register.Password.Length < 6))
                {
                    return(BadRequest());
                }

                else
                {
                    UidwithMessage message = repo.Register(register);

                    if (message.Message.Equals("Ok"))
                    {
                        return(Ok(message));
                    }
                    else if (message.Message.Equals("Invalid Email"))
                    {
                        return(BadRequest());
                    }
                    else if (message.Message.Equals("Username Already Exists !!!"))
                    {
                        return(StatusCode(406));
                    }
                    else
                    {
                        return(StatusCode(422));
                    }
                }
            }
        }
예제 #3
0
        public UidwithMessage VerifyKey(Verification verify)
        {
            VerifyCode     code;
            UidwithMessage ans;

            code = db.VerifyCode.FirstOrDefault(c => c.Uid == verify.Uid && c.Code == verify.Code);
            if (code == null)
            {
                return(ans = new UidwithMessage {
                    Uid = verify.Uid, Message = "Null"
                });
            }
            else
            {
                User user = db.User.FirstOrDefault(c => c.Uid == verify.Uid);
                user.Verified = "true";
                db.User.Update(user);
                db.SaveChanges();
                return(ans = new UidwithMessage {
                    Uid = verify.Uid, Message = "True"
                });
            }
        }
예제 #4
0
        public UidwithMessage Register(Register register)
        {
            User           temp = db.User.FirstOrDefault(c => c.Email.Equals(register.Email));
            UidwithMessage message;
            string         reply;

            if (temp == null)
            {
                User temp1 = db.User.FirstOrDefault(c => c.Uname.Equals(register.UserName));
                if (temp1 == null)
                {
                    var check = new EmailAddressAttribute();
                    if (!check.IsValid(register.Email))
                    {
                        message = new UidwithMessage
                        {
                            Uid     = 0,
                            Message = "Invalid Email"
                        };
                        return(message);
                    }

                    User user = new User
                    {
                        Uname    = register.UserName,
                        Email    = register.Email,
                        Password = register.Password,
                        Verified = "false",
                        Role     = "User"
                    };

                    db.User.Add(user);
                    db.SaveChanges();

                    reply = SendMail(user);



                    if (reply == "Ok")
                    {
                        message = new UidwithMessage
                        {
                            Uid     = user.Uid,
                            Message = reply
                        };
                        return(message);
                    }
                    else
                    {
                        message = new UidwithMessage
                        {
                            Uid     = 0,
                            Message = reply
                        };
                        db.User.Remove(user);
                        return(message);
                    }
                }
                else
                {
                    reply   = "Username Already Exists !!!";
                    message = new UidwithMessage
                    {
                        Uid     = 0,
                        Message = reply
                    };
                    return(message);
                }
            }
            else
            {
                reply   = "Email Already Exists !!!";
                message = new UidwithMessage
                {
                    Uid     = 0,
                    Message = reply
                };
                return(message);
            }
        }