Exemplo n.º 1
0
        public virtual Acknowledgement <User> Validate(string UserEmail, string UserPassword)
        {
            Regex Email    = new Regex(@"^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$");
            Regex Password = new Regex(@"(?=^.{6,20}$)(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&amp;*()_+}{&quot;:;'?/&gt;.&lt;,])(?!.*\s).*$");

            try
            {
                if (!Email.IsMatch(UserEmail) || !Password.IsMatch(UserPassword))
                {
                    acknowledgement.code    = 3;
                    acknowledgement.Set     = null;
                    acknowledgement.Message = "Invalid Credentials";
                    return(acknowledgement);
                }
                //UserService userService = new UserService();
                List <User>     list  = signup.GetDetails();
                List <User>     users = new List <User>();
                PasswordHashing hash  = new PasswordHashing();
                foreach (User user in list)
                {
                    if (user.UserEmail.Equals(UserEmail,
                                              StringComparison.OrdinalIgnoreCase) && (hash.IsPasswordValid(UserPassword, user.UserPassword) && !user.UserType.Equals("Admin")))
                    {
                        users.Add(user);
                    }
                    else if (user.UserEmail.Equals(UserEmail,
                                                   StringComparison.OrdinalIgnoreCase) && UserPassword.Equals(user.UserPassword) && user.UserType.Equals("Admin"))
                    {
                        users.Add(user);
                    }
                }
                if (users.Count == 1 && users[0].UserStatus.ToLower().Equals("invalid"))
                {
                    acknowledgement.code    = 0;
                    acknowledgement.Set     = users;
                    acknowledgement.Message = "Sorry! Account is Blocked";
                }
                else if (users.Count == 1)
                {
                    acknowledgement.code    = 1;
                    acknowledgement.Set     = users;
                    acknowledgement.Message = "Successfully LoggedIn";
                }
                else if (users.Count != 1)
                {
                    acknowledgement.code    = 0;
                    acknowledgement.Set     = users;
                    acknowledgement.Message = "Invalid Credentials";
                }
                return(acknowledgement);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
        //This method will do validations for existance of email and type of partner and if not exists it inserts data.
        public virtual Acknowledgement <User> PostUser(HelperAddUser adduser)
        {
            User user  = new User();
            int  count = 0;

            try
            {
                user.UserName        = adduser.UserName;
                user.UserEmail       = adduser.Email;
                user.UserPhoneNumber = adduser.MobileNumber;
                user.UserAddress     = adduser.Address;
                user.UserPassword    = adduser.Password;
                user.UserType        = adduser.Type;
                user.UserStatus      = "valid";
                List <User> users = new List <User>();
                users.Add(user);
                string validator = validations(user);
                if (!validator.Equals("success"))
                {
                    acknowledgement.code    = 2;
                    acknowledgement.Set     = null;
                    acknowledgement.Message = validator;
                    return(acknowledgement);
                }
                else
                {
                    string name    = user.UserName.Trim();
                    string address = user.UserAddress.Trim();
                    if ((name.Equals("")) && (address.Equals("")))
                    {
                        acknowledgement.code    = 2;
                        acknowledgement.Set     = null;
                        acknowledgement.Message = "Username field and address field should not empty";
                        return(acknowledgement);
                    }
                    if (name.Equals(""))
                    {
                        acknowledgement.code    = 2;
                        acknowledgement.Set     = null;
                        acknowledgement.Message = "Fullname field should not empty";
                        return(acknowledgement);
                    }
                    if (address.Equals(""))
                    {
                        acknowledgement.code    = 2;
                        acknowledgement.Set     = null;
                        acknowledgement.Message = "Address field should not be empty";
                        return(acknowledgement);
                    }
                    foreach (var item in signup.Getdata())
                    {
                        if ((item.UserEmail.Equals(user.UserEmail, StringComparison.OrdinalIgnoreCase)))
                        {
                            count++;
                        }
                    }
                    if (count == 0)
                    {
                        PasswordHashing hash     = new PasswordHashing();
                        string          password = "";
                        acknowledgement.code    = 0;
                        acknowledgement.Set     = null;
                        acknowledgement.Message = "Successfully Registered.";
                        password          = hash.CreatePasswordSalt(user.UserPassword);
                        user.UserPassword = password;
                        signup.PostUser(user);
                        return(acknowledgement);
                    }

                    else
                    {
                        acknowledgement.code    = 2;
                        acknowledgement.Set     = null;
                        acknowledgement.Message = "This account already exists.";
                        return(acknowledgement);
                    }
                    //return acknowledgement;
                }
            }

            catch (Exception e)
            {
                throw e;
            }
        }