Esempio n. 1
0
        public void TestPassValidation <T>(Pass <T> p, bool throwEx) where T : BasePassStyle
        {
            string path = AppDomain.CurrentDomain.BaseDirectory; //Assembly.GetExecutingAssembly().Location;
            var    cwd  = new DirectoryInfo(path).Parent.Parent.Parent;

            path = cwd.FullName;

            var pass  = Helpers.LoadCertificateFromBytes(File.ReadAllBytes(path + "\\resources\\pass.com.eon4u.p12"), "eon4u");
            var apple = Helpers.LoadCertificateFromBytes(File.ReadAllBytes(path + "\\resources\\AppleWWDRCA.cer"));
            var opt   = new PassGeneratorOptions {
                PassCert = pass, AppleCert = apple
            };

            var passGenerator = new PassGenerator(opt);

            try
            {
                passGenerator.ValidatePass(p);
                Xunit.Assert.False(throwEx);
            }
            catch (Exception ex)
            {
                Xunit.Assert.True(throwEx);
            }
        }
Esempio n. 2
0
        //https://webServiceURL/version/passes/passTypeIdentifier/serialNumber
        public HttpResponseMessage GetPass(string version, string passTypeIdentifier, string serialNumber)
        {
            EventPassGeneratorRequest request = new EventPassGeneratorRequest();

            request.Identifier       = "pass.tomsamcguinness.events";
            request.CertThumbprint   = ConfigurationManager.AppSettings["PassBookCertificateThumbprint"];
            request.CertLocation     = System.Security.Cryptography.X509Certificates.StoreLocation.CurrentUser;
            request.SerialNumber     = "121212111";
            request.Description      = "My first pass";
            request.OrganizationName = "Tomas McGuinness";
            request.TeamIdentifier   = "Team America";
            request.LogoText         = "My Pass";
            request.BackgroundColor  = "#000000";
            request.ForegroundColor  = "#FFFFFF";

            request.ImagesPath = HttpContext.Current.Server.MapPath(@"~/Icons/Starbucks/");

            // Specific information
            //
            request.EventName      = "Jeff Wayne's War of the Worlds";
            request.SeatingSection = 10;
            request.DoorsOpen      = new DateTime(2012, 11, 04, 11, 30, 00); // move the date!
            request.AddBarCode("01927847623423234234", BarcodeType.PKBarcodeFormatPDF417, "UTF-8", "01927847623423234234");

            request.AuthenticationToken = "vxwxd7J8AlNNFPS8k0a0FfUFtq0ewzFdc";
            request.WebServiceUrl       = "http://192.168.1.3:81/api/";

            PassGenerator generator     = new PassGenerator();
            Pass          generatedPass = generator.Generate(request);

            var response = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new ObjectContent <Byte[]>(generatedPass.GetPackage(), new BinaryFormatter());
            return(response);
        }
Esempio n. 3
0
        public ActionResult EventTicket()
        {
            PassGenerator generator = new PassGenerator();

            EventPassGeneratorRequest request = new EventPassGeneratorRequest();

            request.Identifier       = "pass.tomsamcguinness.events";
            request.CertThumbprint   = ConfigurationManager.AppSettings["PassBookCertificateThumbprint"];
            request.CertLocation     = System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine;
            request.SerialNumber     = "121211";
            request.Description      = "My first pass";
            request.OrganizationName = "Tomas McGuinness";
            request.TeamIdentifier   = "R5QS56362W";
            request.LogoText         = "My Pass";
            request.BackgroundColor  = "rgb(255,255,255)";
            request.ForegroundColor  = "rgb(0,0,0)";

            // override icon and icon retina
            request.Images.Add(PassbookImage.Icon, System.IO.File.ReadAllBytes(Server.MapPath("~/Icons/icon.png")));
            request.Images.Add(PassbookImage.IconRetina, System.IO.File.ReadAllBytes(Server.MapPath("~/Icons/[email protected]")));

            request.EventName      = "Jeff Wayne's War of the Worlds";
            request.SeatingSection = 10;
            request.DoorsOpen      = new DateTime(2012, 11, 03, 11, 30, 00);

            request.AddBarCode("01927847623423234234", BarcodeType.PKBarcodeFormatPDF417, "UTF-8", "01927847623423234234");

            byte[] generatedPass = generator.Generate(request);
            return(new FileContentResult(generatedPass, "application/vnd.apple.pkpass"));
        }
Esempio n. 4
0
        public ActionResult Coupon()
        {
            PassGenerator generator = new PassGenerator();

            CouponPassGeneratorRequest request = new CouponPassGeneratorRequest();

            request.PassTypeIdentifier     = "pass.passverse.com.public";
            request.Certificate            = System.IO.File.ReadAllBytes(@"C:\Development\TestMDM\Certificates\SSL Certificates\SSL.pfx");
            request.CertificatePassword    = "******";
            request.AppleWWDRCACertificate = System.IO.File.ReadAllBytes(@"C:\Users\gtmx\Downloads\AppleIncRootCertificate.cer");
            request.SerialNumber           = "121211";
            request.Description            = "My first pass";
            request.OrganizationName       = "Tomas McGuinness";
            request.TeamIdentifier         = "R5QS56362W";
            request.LogoText        = "My Pass";
            request.BackgroundColor = "rgb(0,0,0)";
            request.ForegroundColor = "rgb(255,255,255)";

            request.AssociatedStoreIdentifiers.Add(551768476);
            request.AppLaunchURL = "something-goes-here";

            // override icon and icon retina
            request.Images.Add(PassbookImage.Icon, System.IO.File.ReadAllBytes(Server.MapPath("~/Icons/icon.png")));
            request.Images.Add(PassbookImage.Icon2X, System.IO.File.ReadAllBytes(Server.MapPath("~/Icons/[email protected]")));
            request.Images.Add(PassbookImage.Icon3X, System.IO.File.ReadAllBytes(Server.MapPath("~/Icons/[email protected]")));

            request.AddBarcode(BarcodeType.PKBarcodeFormatPDF417, "01927847623423234234", "UTF-8", "01927847623423234234");

            byte[] generatedPass = generator.Generate(request);

            return(new FileContentResult(generatedPass, "application/vnd.apple.pkpass"));
        }
Esempio n. 5
0
 public void ValidatePasswordInitialize()
 {
     Generator  = new PassGenerator();
     Validator  = new PassValidator(Generator);
     TestUserId = "Test user";
     StartTime  = DateTime.Now;
 }
        public ActionResult Coupon()
        {
            return(View());

            PassGenerator generator = new PassGenerator();

            CouponPassGeneratorRequest request = new CouponPassGeneratorRequest();

            request.PassTypeIdentifier = "pass.passverse.com.public";
            request.CertThumbprint     = ConfigurationManager.AppSettings["PassBookCertificateThumbprint"];
            request.CertLocation       = System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine;
            request.SerialNumber       = "121211";
            request.Description        = "My first pass";
            request.OrganizationName   = "Tomas McGuinness";
            request.TeamIdentifier     = "R5QS56362W";
            request.LogoText           = "My Pass";
            request.BackgroundColor    = "rgb(0,0,0)";
            request.ForegroundColor    = "rgb(255,255,255)";

            request.AssociatedStoreIdentifiers.Add(551768476);

            // override icon and icon retina
            request.Images.Add(PassbookImage.Icon, System.IO.File.ReadAllBytes(Server.MapPath("~/Icons/icon.png")));
            request.Images.Add(PassbookImage.IconRetina, System.IO.File.ReadAllBytes(Server.MapPath("~/Icons/[email protected]")));

            request.AddBarcode(BarcodeType.PKBarcodeFormatPDF417, "01927847623423234234", "UTF-8", "01927847623423234234");

            byte[] generatedPass = generator.Generate(request);

            return(new FileContentResult(generatedPass, "application/vnd.apple.pkpass"));
        }
Esempio n. 7
0
 public void VerifyDataInitialize()
 {
     Generator  = new PassGenerator();
     TestUserId = "Test user";
     StartTime  = DateTime.Now;
     User       = new LoginData()
     {
         UserId = TestUserId, TimeStamp = StartTime, PasswordUsed = false
     };
     Generator.Repository.Insert(User);
 }
Esempio n. 8
0
        public void Guardar(AltaEmpresaForm form, Empresa empresa)
        {
            DialogResult dialogResult = MessageBox.Show("Al dar de alta la empresa autogenerará un usuario para la misma. ¿Desea continuar?",
                                                        "Solicitud de confirmación", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                var user = empresa.cuit;
                var pass = PassGenerator.CreateRandomPassword(20);
                CreadorDeUsuarios.CrearNuevaEmpresa(empresa, user, pass, true);
                form.Close();
                new UsuarioPassForm(user, pass).ShowDialog();
            }
        }
Esempio n. 9
0
        public void SecondBasic()
        {
            string path = AppDomain.CurrentDomain.BaseDirectory; //Assembly.GetExecutingAssembly().Location;
            var    cwd  = new DirectoryInfo(path).Parent.Parent.Parent;

            path = cwd.FullName;

            var images = new SerializableDictionary <Enums.PassbookImageType, byte[]>();

            images.Add(Enums.PassbookImageType.Icon, File.ReadAllBytes(path + "\\resources\\eon4u-logo.png"));
            images.Add(Enums.PassbookImageType.IconRetina, File.ReadAllBytes(path + "\\resources\\eon4u-logo.png"));
            images.Add(Enums.PassbookImageType.LogoRetina, File.ReadAllBytes(path + "\\resources\\eon4u-logo.png"));
            images.Add(Enums.PassbookImageType.Logo, File.ReadAllBytes(path + "\\resources\\eon4u-logo.png"));

            var p = new Pass <StoreCardPassStyle>
            {
                SerialNumber     = "123456789",
                Description      = "test",
                OrganizationName = "Test",
                BackgroundColor  = "rgb(102,153,51)",
                LabelColor       = "rgb(255,255,255)",
                ForegroundColor  = "rgb(255,255,255)",
                PassStyle        = new StoreCardPassStyle
                {
                    PrimaryFields = new List <Field>
                    {
                        new StandardField("name", "A", "K")
                    }
                },
                //Barcode = new Barcode(BarcodeType.PKBarcodeFormatQR, "C03FC299-9D27-47EC-A30C-FA8A0A595C09", "ISO-8859-1", "TO JE TEXT OD SPODAJ"),
                Barcodes = new List <Barcode>
                {
                    new Barcode(BarcodeType.PKBarcodeFormatQR, "C03FC299-9D27-47EC-A30C-FA8A0A595C09", "ISO-8859-1")
                },
                Images = images,
            };


            var pass  = Helpers.LoadCertificateFromBytes(File.ReadAllBytes(path + "\\resources\\pass.com.eon4u.p12"), "eon4u");
            var apple = Helpers.LoadCertificateFromBytes(File.ReadAllBytes(path + "\\resources\\AppleWWDRCA.cer"));
            var opt   = new PassGeneratorOptions {
                PassCert = pass, AppleCert = apple
            };

            var passGenerator = new PassGenerator(opt);

            byte[] pkPass = passGenerator.Generate(p);
            File.WriteAllBytes(path + "\\resources\\pass.pkpass", pkPass);
        }
Esempio n. 10
0
        public ActionResult BoardingCard()
        {
            PassGenerator generator = new PassGenerator();

            BoardingCardGeneratorRequest request = new BoardingCardGeneratorRequest();

            request.Identifier       = "pass.tomsamcguinness.events";
            request.CertThumbprint   = ConfigurationManager.AppSettings["PassBookCertificateThumbprint"];
            request.CertLocation     = System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine;
            request.FormatVersion    = 1;
            request.SerialNumber     = "121212111";
            request.Description      = "My first pass";
            request.OrganizationName = "Tomas McGuinness";
            request.TeamIdentifier   = "R5QS56362W";
            request.LogoText         = "My Pass";
            request.BackgroundColor  = "#000000";
            request.ForegroundColor  = "#FFFFFF";

            request.BackgroundFile       = Server.MapPath(@"~/Icons/Starbucks/background.png");
            request.BackgroundRetinaFile = Server.MapPath(@"~/Icons/Starbucks/[email protected]");

            request.IconFile       = Server.MapPath(@"~/Icons/Starbucks/icon.png");
            request.IconRetinaFile = Server.MapPath(@"~/Icons/Starbucks/[email protected]");

            request.LogoFile       = Server.MapPath(@"~/Icons/Starbucks/logo.png");
            request.LogoRetinaFile = Server.MapPath(@"~/Icons/Starbucks/[email protected]");

            // Specific information
            //
            request.Origin     = "San Francisco";
            request.OriginCode = "SFO";

            request.Destination     = "London";
            request.DestinationCode = "LDN";

            request.Seat          = "7A";
            request.BoardingGate  = "F12";
            request.PassengerName = "John Appleseed";

            request.TransitType = TransitType.PKTransitTypeAir;

            request.AuthenticationToken = "vxwxd7J8AlNNFPS8k0a0FfUFtq0ewzFdc";
            request.WebServiceUrl       = "http://192.168.1.59:82/api/";

            Pass generatedPass = generator.Generate(request);

            return(new FileContentResult(generatedPass.GetPackage(), "application/vnd.apple.pkpass"));
        }
        public void Guardar(AltaCliente form, Cliente cliente)
        {
            DialogResult dialogResult = MessageBox.Show("Al crear este cliente autogenerará su usuario y contraseña. ¿Desea continuar?",
                                                        "Solicitud de confirmación", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                var user     = cliente.nroDocumento;
                var password = PassGenerator.CreateRandomPassword(20);
                DataBase.GetInstance().WithTransaction(() =>
                {
                    var idCliente = CreadorDeUsuarios.CrearNuevoCliente(cliente, user, password, true);
                    form.tarjetaAGuardar.SerAsignadaA(idCliente);
                });
                form.Close();
                new UsuarioPassForm(user, password).ShowDialog();
            }
        }
        //https://webServiceURL/version/passes/passTypeIdentifier/serialNumber
        public HttpResponseMessage GetPass(string version, string passTypeIdentifier, string serialNumber)
        {
            StoreCardGeneratorRequest request = new StoreCardGeneratorRequest();

            request.Identifier       = "pass.tomsamcguinness.events";
            request.CertThumbprint   = ConfigurationManager.AppSettings["PassBookCertificateThumbprint"];
            request.CertLocation     = System.Security.Cryptography.X509Certificates.StoreLocation.CurrentUser;
            request.FormatVersion    = 1;
            request.SerialNumber     = "121212111";
            request.Description      = "My first pass";
            request.OrganizationName = "Tomas McGuinness";
            request.TeamIdentifier   = "Team America";
            request.LogoText         = "My Pass";
            request.BackgroundColor  = "#000000";
            request.ForegroundColor  = "#FFFFFF";

            request.BackgroundFile       = HttpContext.Current.Server.MapPath(@"~/Icons/Starbucks/background.png");
            request.BackgroundRetinaFile = HttpContext.Current.Server.MapPath(@"~/Icons/Starbucks/[email protected]");

            request.IconFile       = HttpContext.Current.Server.MapPath(@"~/Icons/Starbucks/icon.png");
            request.IconRetinaFile = HttpContext.Current.Server.MapPath(@"~/Icons/Starbucks/[email protected]");

            request.LogoFile       = HttpContext.Current.Server.MapPath(@"~/Icons/Starbucks/logo.png");
            request.LogoRetinaFile = HttpContext.Current.Server.MapPath(@"~/Icons/Starbucks/[email protected]");

            // Specific information
            //
            request.Balance    = 121.12;
            request.OwnersName = "Tomas McGuinness";
            request.Title      = "Starbucks";
            request.AddBarCode("01927847623423234234", BarcodeType.PKBarcodeFormatPDF417, "UTF-8", "01927847623423234234");

            request.AuthenticationToken = "vxwxd7J8AlNNFPS8k0a0FfUFtq0ewzFdc";
            request.WebServiceUrl       = "http://192.168.1.3:81/api/";

            PassGenerator generator     = new PassGenerator();
            Pass          generatedPass = generator.Generate(request);

            var response = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new ObjectContent <Byte[]>(generatedPass.GetPackage(), new BinaryFormatter());
            return(response);
        }
        public async Task <IActionResult> Login(Login login)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View());
                }
                else
                {
                    string userLogin = login.User;
                    string userPass  = login.Password;

                    var user = await _context.Users.SingleOrDefaultAsync(u => u.Login == userLogin);

                    if (user != null)
                    {
                        if (userPass == PassGenerator.Decrypt(user.Password))
                        {
                            HttpContext.Session.SetString("Name", user.Name);
                            HttpContext.Session.SetInt32("UserID", user.ID);
                            HttpContext.Session.SetString("UserName", user.Login);
                            HttpContext.Session.SetString("UserEmail", user.Email);

                            return(RedirectToAction("Index", "Home"));
                        }
                        else
                        {
                            throw new Exception("Senha inválida.");
                        }
                    }
                    else
                    {
                        throw new Exception("Usuário não encontrado.");
                    }
                }
            }
            catch (Exception e)
            {
                ViewBag.Error = e.Message;
                return(View());
            }
        }
Esempio n. 14
0
        public ActionResult StoreCard()
        {
            PassGenerator generator = new PassGenerator();

            StoreCardGeneratorRequest request = new StoreCardGeneratorRequest();

            request.Identifier       = "pass.tomsamcguinness.events";
            request.CertThumbprint   = ConfigurationManager.AppSettings["PassBookCertificateThumbprint"];
            request.CertLocation     = System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine;
            request.FormatVersion    = 1;
            request.SerialNumber     = "121212111";
            request.Description      = "My first pass";
            request.OrganizationName = "Tomas McGuinness";
            request.TeamIdentifier   = "R5QS56362W";
            request.LogoText         = "My Pass";
            request.BackgroundColor  = "#000000";
            request.ForegroundColor  = "#FFFFFF";

            request.BackgroundFile       = Server.MapPath(@"~/Icons/Starbucks/background.png");
            request.BackgroundRetinaFile = Server.MapPath(@"~/Icons/Starbucks/[email protected]");

            request.IconFile       = Server.MapPath(@"~/Icons/Starbucks/icon.png");
            request.IconRetinaFile = Server.MapPath(@"~/Icons/Starbucks/[email protected]");

            request.LogoFile       = Server.MapPath(@"~/Icons/Starbucks/logo.png");
            request.LogoRetinaFile = Server.MapPath(@"~/Icons/Starbucks/[email protected]");

            // Specific information
            //
            request.Balance    = 100.12;
            request.OwnersName = "Tomas McGuinness";
            request.Title      = "Starbucks";
            request.AddBarCode("01927847623423234234", BarcodeType.PKBarcodeFormatPDF417, "UTF-8", "01927847623423234234");

            request.AuthenticationToken = "vxwxd7J8AlNNFPS8k0a0FfUFtq0ewzFdc";
            request.WebServiceUrl       = "http://192.168.1.59:82/api/";

            Pass generatedPass = generator.Generate(request);

            return(new FileContentResult(generatedPass.GetPackage(), "application/vnd.apple.pkpass"));
        }
        public async Task <IActionResult> Register(User usuario)
        {
            try
            {
                //Just verify if there is any user with the same nickName
                if (await _context.Memories.CountAsync() > 0)
                {
                    foreach (var user in await _context.Users.ToListAsync())
                    {
                        if (user.Login == usuario.Login)
                        {
                            throw new Exception("Não foi possível realizar o cadastro, nome de usuário já utilizado!");
                        }

                        if (user.Email == usuario.Email)
                        {
                            throw new Exception("Não foi possível realizar o cadastro, email já utilizado por outro usuário!");
                        }
                    }
                }

                usuario.Password = PassGenerator.Encrypt(usuario.Password);

                if (ModelState.IsValid)
                {
                    _context.Users.Add(usuario);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Login"));
                }
                else
                {
                    return(View());
                }
            }
            catch (Exception e)
            {
                ViewBag.Error = e.Message;
                return(View());
            }
        }
Esempio n. 16
0
        protected IHttpActionResult GeneratePass(PassProvider provider, string serialNumber)
        {
            PassGeneratorRequest request = provider.GetPass(serialNumber);

            if (request != null)
            {
                // Passbook webService is configured, enable it in the generated pass
                if (!string.IsNullOrEmpty(mServiceUrl))
                {
                    request.WebServiceUrl       = mServiceUrl;
                    request.AuthenticationToken = GenerateAuthorizationToken(provider.PassTypeIdentifier, request.SerialNumber);
                }

                PassGenerator passGenerator = new PassGenerator();
                byte[]        pass          = passGenerator.Generate(request);

                return(new PassbookContentResult(pass));
            }

            return(null);
        }
        public async Task <IActionResult> ChangePassword(ChangePassword _changePassword)
        {
            ViewBag.userName = HttpContext.Session.GetString("UserName");
            ViewBag.userID   = HttpContext.Session.GetInt32("UserID");

            try
            {
                User usuario = await _context.Users.FindAsync(_changePassword.Id);

                if (PassGenerator.Decrypt(usuario.Password) != _changePassword.SenhaAntiga)
                {
                    throw new Exception("Senha antiga inválida!");
                }
                else
                {
                    if (_changePassword.NovaSenha == PassGenerator.Decrypt(usuario.Password))
                    {
                        throw new Exception("A nova senha tem que ser diferente da antiga.");
                    }

                    if (_changePassword.NovaSenha != _changePassword.RepeteNovaSenha)
                    {
                        throw new Exception("As senhas devem ser iguais.");
                    }

                    usuario.Password = PassGenerator.Encrypt(_changePassword.NovaSenha);

                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Index", "Home", new { id = usuario.ID }));
                }
            }
            catch (Exception e)
            {
                ViewBag.Error = e.Message;
                return(View());
            }
        }
Esempio n. 18
0
        public ActionResult EventTicket()
        {
            PassGenerator generator = new PassGenerator();

            EventPassGeneratorRequest request = new EventPassGeneratorRequest();

            request.Identifier       = "pass.tomsamcguinness.events";
            request.CertThumbprint   = ConfigurationManager.AppSettings["PassBookCertificateThumbprint"];
            request.CertLocation     = System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine;
            request.FormatVersion    = 1;
            request.SerialNumber     = "121211";
            request.Description      = "My first pass";
            request.OrganizationName = "Tomas McGuinness";
            request.TeamIdentifier   = "R5QS56362W";
            request.LogoText         = "My Pass";
            request.BackgroundColor  = "#FFFFFF";
            request.ForegroundColor  = "#000000";

            request.BackgroundFile       = Server.MapPath(@"~/Icons/Starbucks/background.png");
            request.BackgroundRetinaFile = Server.MapPath(@"~/Icons/Starbucks/[email protected]");

            request.IconFile       = Server.MapPath(@"~/Icons/icon.png");
            request.IconRetinaFile = Server.MapPath(@"~/Icons/[email protected]");

            request.LogoFile       = Server.MapPath(@"~/Icons/logo.png");
            request.LogoRetinaFile = Server.MapPath(@"~/Icons/[email protected]");

            request.EventName      = "Jeff Wayne's War of the Worlds";
            request.SeatingSection = 10;
            request.DoorsOpen      = new DateTime(2012, 11, 03, 11, 30, 00);

            request.AddBarCode("01927847623423234234", BarcodeType.PKBarcodeFormatPDF417, "UTF-8", "01927847623423234234");

            Pass generatedPass = generator.Generate(request);

            return(new FileContentResult(generatedPass.GetPackage(), "application/vnd.apple.pkpass"));
        }
Esempio n. 19
0
        protected bool SetSessionKey()
        {
            bool bRez = true;

            if (HttpContext.Current.Session[Constants.SessionID] == null)
            {
                using (Nostralogia2._1.SMParamKeeper.SMParamKeeperServClient serv = new Nostralogia2._1.SMParamKeeper.SMParamKeeperServClient())
                {
                    PassGenerator passgen = new PassGenerator();
                    passgen.Numbers         = true;
                    passgen.NumberSymbols   = Constants.LengthSalt;
                    passgen.SmallLetters    = true;
                    passgen.CapitalsLetters = true;
                    passgen.SpecialSymbols  = true;
                    passgen.Generate();
                    String salt = passgen.Pass;
                    HttpContext.Current.Session[Constants.SessionSalt] = salt;

                    passgen.NumberSymbols = Constants.LengthPassphrase;
                    passgen.Generate();
                    String pass = passgen.Pass;
                    HttpContext.Current.Session[Constants.SessionPass] = pass;

                    DateTime dt = DateTime.Now.AddHours(24);
                    try
                    {
                        serv.SetSessionKey(ADUtilities.GetSessionGUID(), salt, pass, String.Format("{0}-{1}-{2}", dt.Year, dt.Month, dt.Day));
                    }
                    catch (Exception ex)
                    {
                        bRez = false;
                        FormatAndLogMessage("SetSessionKey", ex.Message);
                    }
                }
            }
            return(bRez);
        }
Esempio n. 20
0
 public static void AddPass(PassGenerator pass, string name)
 {
     passes.Add(pass);
     passNameList.Add(name);
     passNameArray = null; // reset so you can't accidentally use it when it's out of date
 }
Esempio n. 21
0
        public byte[] GetPass2(HttpContextBase context, CouponInfoResponse coupponInfo)
        {
            var generator = new PassGenerator();

            var request = new CouponPassGeneratorRequest
            {
                Identifier     = ConfigurationManager.AppSettings["Identifier"],
                CertThumbprint =
                    ConfigurationManager.AppSettings["PassBookCertificateThumbprint"].Replace(" ", String.Empty),
                CertLocation               = System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine,
                SerialNumber               = coupponInfo.Id.ToString(CultureInfo.InvariantCulture),
                Description                = coupponInfo.ProductDescription,
                OrganizationName           = ConfigurationManager.AppSettings["OrganizationName"],
                TeamIdentifier             = ConfigurationManager.AppSettings["TeamIdentifier"],
                BackgroundColor            = "rgb(229,1,80)",
                ForegroundColor            = "rgb(255,255,255)",
                LabelColor                 = "rgb(255,255,255)",
                AssociatedStoreIdentifiers = new List <int>(1)
                {
                    ConfigManager.AppleAppid
                }
            };


            // override icon and icon retina
            request.Images.Add(PassbookImage.Icon, System.IO.File.ReadAllBytes(context.Server.MapPath("~/Icons/coupon/icon.png")));
            request.Images.Add(PassbookImage.Logo, System.IO.File.ReadAllBytes(context.Server.MapPath("~/Icons/coupon/logo.png")));
            request.AddBarCode(coupponInfo.CouponId, BarcodeType.PKBarcodeFormatPDF417, "iso-8859-1" /*"UTF-8"*/, coupponInfo.CouponId);
            request.SuppressStripShine = false;

            //获取品牌 ,获取 STORE
            var store  = GetStore(coupponInfo);
            var brands = GetBrand(coupponInfo);

            string bName = String.Empty;

            //折扣部分
            if (brands.Count > 0)
            {
                bName = brands[0].Name;
            }

            if (coupponInfo.SourceType == (int)SourceType.Product)
            {
                request.AddPrimaryField(new StandardField("primary1", bName, coupponInfo.ProductName));
            }

            if (coupponInfo.SourceType == (int)SourceType.Promotion)
            {
                request.AddPrimaryField(new StandardField("primary1", String.Empty, coupponInfo.ProductName));
            }

            //有效期

            request.AddSecondaryField(new DateField("secondary1", "有效期", coupponInfo.ValidStartDate, FieldDateTimeStyle.PKDateStyleLong, FieldDateTimeStyle.PKDateStyleNone));
            //
            request.AddSecondaryField(new StandardField("secondary2", String.Empty, "-"));

            request.AddSecondaryField(new DateField("secondary3", String.Empty, coupponInfo.ValidEndDate, FieldDateTimeStyle.PKDateStyleLong, FieldDateTimeStyle.PKDateStyleNone));

            request.AddBackField(new StandardField("back info1", coupponInfo.ProductName, coupponInfo.ProductDescription));
            request.AddBackField(new StandardField("back info2", "有效期", String.Format("{0} - {1}", coupponInfo.ValidStartDate.ToString("yyyy-M-d"), coupponInfo.ValidEndDate.ToString("yyyy-M-d"))));

            if (store != null)
            {
                request.LogoText = store.Name;//couponName;

                request.AddBackField(new StandardField("address", "地址", store.Location));
                request.AddBackField(new StandardField("ad2", "联系电话", store.Tel));
                var relevantest = String.Format("您附近的{0}正在做促销,详情进店查看", store.Name);
                request.Locations.Add(
                    new Location
                {
                    Latitude     = (double)store.Latitude,
                    Longitude    = (double)store.Longitude,
                    RelevantText = relevantest
                });

                if (store.GpsLat != null && store.GpsLng != null)
                {
                    request.Locations.Add(new Location
                    {
                        Latitude     = (double)store.GpsLat.Value,
                        Longitude    = (double)store.GpsLng.Value,
                        RelevantText = relevantest
                    });
                }
            }

            byte[] generatedPass = generator.Generate(request);

            return(generatedPass);

            //return null;
        }