Exemplo n.º 1
0
        public async Task <Boolean> RegisterCustomer(Customer customer)
        {
            var email = customer.Email;

            customer.Pass_word = HashAndSalt.HashSalt(customer.Pass_word);
            using (IDbConnection dbConnection = Connection)
            {
                string sQuery0 = "SELECT FirstName FROM Customer WHERE Email = @email";
                dbConnection.Open();
                String result = dbConnection.QueryFirstOrDefault <String>(sQuery0, new { @Email = email });
                dbConnection.Close();

                if (string.IsNullOrEmpty(result))
                {
                    customer.VerifiCode = VerifiCodeGenarator.CreateRandomPassword();
                    customer.Validated  = false;
                    string sQuery = "INSERT INTO Customer(FirstName,LastName,Pass_word,Email,MobileNo,VerifiCode,Validated)" +
                                    "VALUES(@FirstName,@LastName,@Pass_word,@Email,@MobileNo,@VerifiCode,@Validated)";

                    dbConnection.Open();
                    //dbConnection.Execute(sQuery, new { customer.FirstName = FirstName , VerifiCode = vCode });
                    dbConnection.Execute(sQuery, customer);
                    Senders emailsender = new Senders();
                    await emailsender.SendEmailAsync("*****@*****.**", customer.VerifiCode);

                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        public UserModel RegisterShopOwner(ShopOwner shopowner)
        {
            var email = shopowner.Email;

            shopowner.Pass_word = HashAndSalt.HashSalt(shopowner.Pass_word);
            using (IDbConnection dbConnection = Connection)
            {
                string sQuery0 = "SELECT FirstName FROM ShopOwner WHERE Email = @email";
                dbConnection.Open();
                String result = dbConnection.QueryFirstOrDefault <String>(sQuery0, new { @Email = email });
                dbConnection.Close();

                if (string.IsNullOrEmpty(result))
                {
                    String VerifiCode = VerifiCodeGenarator.CreateRandomPassword();
                    shopowner.VerifiCode = VerifiCode;
                    shopowner.Validated  = false;
                    string sQuery = "INSERT INTO ShopOwner(FirstName,LastName,Pass_word,Email,MobileNo,VerifiCode,Validated)" +
                                    "VALUES(@FirstName,@LastName,@Pass_word,@Email,@MobileNo,@VerifiCode,@Validated)";

                    dbConnection.Open();
                    dbConnection.Execute(sQuery, shopowner);
                    dbConnection.Close();

                    SendMail(email, VerifiCode);

                    string sQuery1 = "SELECT ShopOwnerId from ShopOwner where Email = @email";
                    string ID      = dbConnection.QueryFirstOrDefault <String>(sQuery1, new { @Email = email });

                    UserModel user = null;
                    user = new UserModel {
                        Id = ID, Name = shopowner.FirstName, Email = shopowner.Email
                    };
                    //String Token = BuildToken(user);
                    //return new OkObjectResult(new { token = Token });
                    return(user);
                }

                return(null);
            }

            /* var method = typeof(TokenCreator).GetMethod("createToken");
             * var action = (Action<TokenCreator>)Delegate.CreateDelegate(typeof(Action<TokenCreator>), method);
             * action(user);*/

            //TokenCreator tokencreator = new TokenCreatorC();
            //return tokencreator.createToken(user);
        }
        public UserModel LoginCustomer(Login login)
        {
            String checkUserName;
            string ID;

            login.Pass_word = HashAndSalt.HashSalt(login.Pass_word);

            var email    = login.Email;
            var password = login.Pass_word;

            using (IDbConnection dbConnection = Connection)
            {
                string sQuery  = "SELECT FirstName FROM Customer WHERE Email = @Email AND Pass_word = @Pass_word";
                string sQuery1 = "SELECT CustomerId from Customer where Email = @email";

                dbConnection.Open();
                checkUserName = dbConnection.QueryFirstOrDefault <String>(sQuery, new { @Email = email, @Pass_word = password });
                dbConnection.Close();
                dbConnection.Open();
                ID = dbConnection.QueryFirstOrDefault <String>(sQuery1, new { @Email = email });
                dbConnection.Close();
            }

            if (String.IsNullOrEmpty(checkUserName))
            {
                return(null);
            }
            else
            {
                UserModel user = null;
                user = new UserModel {
                    Id = ID, Name = checkUserName, Email = email
                };
                return(user);

                /* var method = typeof(TokenCreator).GetMethod("createToken");
                 * var action = (Action<TokenCreator>)Delegate.CreateDelegate(typeof(Action<TokenCreator>), method);
                 * action(user);*/

                //TokenCreator tokencreator = new TokenCreatorC();
                //return tokencreator.createToken(user);
            }
        }
        public bool LoginAdmin(Login login)
        {
            login.Pass_word = HashAndSalt.HashSalt(login.Pass_word);

            var o = login.Email;
            var i = login.Pass_word;

            using (IDbConnection dbConnection = Connection)
            {
                string sQuery = "SELECT FirstName FROM Administer WHERE Email = @Email AND Pass_word = @Pass_word";
                dbConnection.Open();
                checkExist = dbConnection.QueryFirstOrDefault <String>(sQuery, new { @Email = o, @Pass_word = i });
            }

            if (String.IsNullOrEmpty(this.checkExist))
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
        public bool RegisterAdmin(Administer administer)
        {
            var email = administer.Email;

            administer.Pass_word = HashAndSalt.HashSalt(administer.Pass_word);
            using (IDbConnection dbConnection = Connection)
            {
                string sQuery0 = "SELECT FirstName FROM Administer WHERE Email = @email";
                dbConnection.Open();
                String result = dbConnection.QueryFirstOrDefault <String>(sQuery0, new { @Email = email });
                dbConnection.Close();

                if (string.IsNullOrEmpty(result))
                {
                    string sQuery = "INSERT INTO Administer(FirstName,LastName,Pass_word,Email,MobileNo)" +
                                    "VALUES(@FirstName,@LastName,@Pass_word,@Email,@MobileNo)";

                    dbConnection.Open();
                    dbConnection.Execute(sQuery, administer);
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 6
0
        public async Task <IActionResult> RegisterRider(Rider rider)
        {
            long number;
            var  email = rider.Email;

            rider.Pass_word = HashAndSalt.HashSalt(rider.Pass_word);
            using (IDbConnection dbConnection = Connection)
            {
                string sQuery0 = "SELECT FirstName FROM Rider WHERE Email = @email";
                dbConnection.Open();
                String result = dbConnection.QueryFirstOrDefault <String>(sQuery0, new { @Email = email });
                dbConnection.Close();
                if (string.IsNullOrEmpty(result))
                {
                    rider.VerifiCode = VerifiCodeGenarator.CreateRandomPassword();
                    rider.Validated  = false;
                    string sQuery = "INSERT INTO Rider(FirstName,LastName,Pass_word,Email,MobileNo,VerifiCode,Validated,LicenseNo,Nic)" +
                                    "VALUES(@FirstName,@LastName,@Pass_word,@Email,@MobileNo,@VerifiCode,@Validated,@LicenseNo,@Nic)";

                    dbConnection.Open();
                    dbConnection.Execute(sQuery, rider);
                    dbConnection.Close();
                    string sQuery1 = "SELECT RiderId FROM Rider WHERE Email = @email";
                    dbConnection.Open();
                    String result2 = dbConnection.QueryFirstOrDefault <String>(sQuery1, new { @Email = email });
                    number = Int64.Parse(result2);
                    Image   toupload    = new Image(rider.image, number);
                    Senders emailsender = new Senders();
                    await emailsender.SendEmail(email, rider.VerifiCode);

                    return(await UploadImage(toupload));
                }

                return(new ConflictResult());
            }
        }
Exemplo n.º 7
0
        public ShopUserModel LoginShopOwner(Login login)
        {
            String checkUserName;

            login.Pass_word = HashAndSalt.HashSalt(login.Pass_word);

            var email    = login.Email;
            var password = login.Pass_word;

            using (IDbConnection dbConnection = Connection)
            {
                string sQuery = "SELECT FirstName FROM ShopOwner WHERE Email = @Email AND Pass_word = @Pass_word";
                dbConnection.Open();
                checkUserName = dbConnection.QueryFirstOrDefault <String>(sQuery, new { @Email = email, @Pass_word = password });



                if (String.IsNullOrEmpty(checkUserName))
                {
                    return(null);
                }
                else
                {
                    string OwnerID;
                    string sQuery1 = "SELECT ShopOwnerId from ShopOwner where Email = @email";
                    OwnerID = dbConnection.QueryFirstOrDefault <String>(sQuery1, new { @Email = email });
                    string sQuery2 = "SELECT * FROM Shop WHERE OwnerId = @OwnerID";
                    try
                    {
                        dynamic shop = dbConnection.QueryFirst(sQuery2, new { OwnerId = OwnerID });



                        ShopUserModel shopuser = null;
                        shopuser = new ShopUserModel
                        {
                            ShopId      = shop.ShopId,
                            UId         = OwnerID,
                            Name        = checkUserName,
                            Email       = email,
                            Description = shop.Des_cription,
                            Location    = shop.Lo_cation,
                            ShopName    = shop.ShopName,
                            Url         = shop.url,
                            Lat         = shop.Lat,
                            Lng         = shop.Lng,
                        };

                        return(shopuser);
//                        String Token = BuildShopUserToken(shopuser);
//                        return new OkObjectResult(new { token = Token });
                    }
                    catch (Exception e)
                    {
                        return(null);
                    }

                    /* var method = typeof(TokenCreator).GetMethod("createToken");
                     * var action = (Action<TokenCreator>)Delegate.CreateDelegate(typeof(Action<TokenCreator>), method);
                     * action(user);*/
                } //TokenCreator tokencreator = new TokenCreatorC();

                //return tokencreator.createToken(user);
            }
        }