예제 #1
0
        public void CreatePerson()
        {
            ApplicationConfiguration appApplicationConfiguration = new ApplicationConfiguration();
            PersonRepository         personRepository            = new PersonRepository(_session);
            ScheduledEmailRepository scheduledEmailRepository    = new ScheduledEmailRepository(_session);
            EmailNotificationService emailNotificationService    = new EmailNotificationService(appApplicationConfiguration);
            ScheduledEmailService    scheduledEmailService       = new ScheduledEmailService(scheduledEmailRepository, emailNotificationService, personRepository);
            DeviceRepository         deviceRepository            = new DeviceRepository(_session);
            SessionRepository        sessionRepository           = new SessionRepository(_session);
            PersonService            personService         = new PersonService(personRepository, deviceRepository, sessionRepository, emailNotificationService, scheduledEmailService, appApplicationConfiguration, scheduledEmailRepository);
            SessionService           sessionService        = new SessionService(sessionRepository);
            DeviceService            deviceService         = new DeviceService(deviceRepository, personRepository);
            AuthenticationService    authenticationService = new AuthenticationService(personRepository);

            AuthController authController = new AuthController(sessionService, personService, authenticationService, deviceService)
            {
                Configuration = new HttpConfiguration(),
                Request       = new HttpRequestMessage()
            };

            authController.Request.Headers.Add("XClientId", "00000000000000000000000000000000");

            PersonRegisterModel personRegisterModel = new PersonRegisterModel()
            {
                // assign the data to model properties here
            };

            string jsonString = JsonConvert.SerializeObject(personRegisterModel);

            AuthModelLight authModelLight = authController.CreatePerson(personRegisterModel);

            Assert.AreNotEqual(authModelLight.UserId, 0);
        }
예제 #2
0
        public PersonRegisterModel UpgradePerson(PersonRegisterModel personRegisterModel)
        {
            var personList = _personRepository.FindPersonByEmail(personRegisterModel.PerEmailAddress);

            foreach (var person in personList)
            {
                DeletePerson(person.Id);
            }

            return(CreatePerson(personRegisterModel));
        }
예제 #3
0
        /// <summary>
        /// Modify Person Registration
        /// </summary>
        /// <param name="personRegisterModel">Person Registration Model</param>
        /// <returns>Updated Registered Person</returns>
        public PersonRegisterModel UpdatePerson(PersonRegisterModel personRegisterModel)
        {
            var person = _personRepository.Get(personRegisterModel.PerId);

            //var scheduledEmail = (ScheduledEmail)_scheduledEmailService.GetScheduledEmailsByPersonId(personRegisterModel.PerId).FirstOrNull();

            // Verification Code Email exception occured

            /*if ((scheduledEmail != null) && !scheduledEmail.SchReady && !scheduledEmail.SchEmailed && (person.PerEmail == personRegisterModel.PerEmailAddress))
             * {
             *      throw new Exception("Email Error");
             * }*/

            person.PerEmail     = personRegisterModel.PerEmailAddress;
            person.PerFirstname = personRegisterModel.PerFirstname;
            person.PerLastname  = personRegisterModel.PerLastname;
            //person.PerIdNumber = personRegisterModel.;
            person.PerHashPassword = AuthenticationHelper.GetPasswordHash(personRegisterModel.PerEmailAddress, personRegisterModel.Password);
            //person.VerifyCode = 9999;
            person.PerVerifyCode = (short)_random.Next(1000, 9999);
            person.CreateDate    = personRegisterModel.CreateDate;
            person.ModifiedDate  = personRegisterModel.ModifiedDate;

            using (var transaction = _personRepository.Session.BeginTransaction())
            {
                _personRepository.SaveOrUpdate(person);
                transaction.Commit();
            }

            personRegisterModel = new PersonRegisterModel(person)
            {
                //Password = personRegisterModel.Password,
                Password          = "******",
                DeviceCode        = personRegisterModel.DeviceCode,
                DeviceDescription = personRegisterModel.DeviceDescription,
                OS = personRegisterModel.OS
            };

            //Send Registration Mail

            /*var emailSubject = _notificationService.GetRegisterSubject();
             * var emailBody = _notificationService.GetRegisterMailBody(person);
             * var fromAddress = _applicationConfiguration.GetSetting("from_address");
             * var fromName = _applicationConfiguration.GetSetting("from_name");
             * _scheduledEmailService.CreatScheduledEmail(fromAddress, fromName, person.PerEmail, string.Empty, string.Empty, emailSubject, emailBody, true, ScheduledEmailType.Registration, person.Id);*/

            return(personRegisterModel);
        }
예제 #4
0
        /// <summary>
        /// Person Registration
        /// </summary>
        /// <param name="personRegisterModel">Person Registration Model</param>
        /// <returns>Registered Person</returns>
        public PersonRegisterModel CreatePerson(PersonRegisterModel personRegisterModel)
        {
            var person = new Person
            {
                PerFirstname    = personRegisterModel.PerFirstname,
                PerLastname     = personRegisterModel.PerLastname,
                PerCellPhone    = personRegisterModel.PerCellPhone,
                PerEmail        = personRegisterModel.EmailAddress,
                PerPassword     = personRegisterModel.Password, // remove this as a later stage
                PerHashPassword = AuthenticationHelper.GetPasswordHash(personRegisterModel.EmailAddress, personRegisterModel.Password),
                //VerifyCode = 9999,
                PerVerifyCode    = (short)_random.Next(1000, 9999),
                CreateDate       = DateTime.Now,
                ModifiedDate     = DateTime.Now,
                PerDob           = DateTime.Now,
                PerType          = personRegisterModel.PerType,
                PerEmailVerified = true,
                PerTransportId   = personRegisterModel.PerTransportId
            };

            using (var transaction = _personRepository.Session.BeginTransaction())
            {
                _personRepository.Save(person);
                transaction.Commit();
            }

            personRegisterModel = new PersonRegisterModel(person)
            {
                //Password = personRegisterModel.Password,
                Password          = "******",
                DeviceCode        = personRegisterModel.DeviceCode,
                DeviceDescription = personRegisterModel.DeviceDescription,
                OS = personRegisterModel.OS
            };

            //Send Registration Mail

            /*var emailSubject = _notificationService.GetRegisterSubject();
             * var emailBody = _notificationService.GetRegisterMailBody(person);
             * var fromAddress = _applicationConfiguration.GetSetting("from_address");
             * var fromName = _applicationConfiguration.GetSetting("from_name");
             * _scheduledEmailService.CreatScheduledEmail(fromAddress, fromName, person.PerEmail, string.Empty, string.Empty, emailSubject, emailBody, true, ScheduledEmailType.Registration, person.Id);*/

            return(personRegisterModel);
        }
예제 #5
0
        public AuthModelLight CreatePerson(PersonRegisterModel personRegisterModel)
        {
            try
            {
                string errorInfo;
                var    login = _personService.GetPersonByEmail(personRegisterModel.EmailAddress);

                if (login == null) // Initial Registration
                {
                    var emailRegex = new Regex("^[A-Za-z0-9_\\+-]+(\\.[A-Za-z0-9_\\+-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*\\.([A-Za-z]{2,4})$");
                    if (emailRegex.IsMatch(personRegisterModel.EmailAddress))
                    {
                        // Do extra information validation here...

                        // Create Person
                        personRegisterModel = _personService.CreatePerson(personRegisterModel);
                        AuthModelLight authModelLight = new AuthModelLight
                        {
                            Desc         = "Registered successfully...",
                            PersonId     = personRegisterModel.PerId,
                            EmailAddress = personRegisterModel.EmailAddress,
                            Password     = null, //don't need it here
                            SessionKey   = null  // don't need it here
                        };

                        // Create Device

                        /*DeviceModel deviceModel = new DeviceModel
                        *                       {
                        *                               PersonId = personRegisterModel.PerId,
                        *                               DeviceCode = personRegisterModel.DeviceCode, // firebase token
                        *                               DeviceDescription = personRegisterModel.DeviceDescription,
                        *                               OS = personRegisterModel.OS
                        *                       };
                        *                       _deviceService.CreateDevice(deviceModel);*/

                        return(authModelLight);
                    }

                    errorInfo = ApplicationConfiguration.RegisterEmailInvalid;
                }

                /*else if ((personRegisterModel.ObjectId != 0) && !_personService.IsVerified(personRegisterModel.ObjectId)) // Update Registration and/or Resent Veification Code
                 *              {
                 *                      personRegisterModel = _personService.CreatePerson(personRegisterModel);
                 *                      AuthModelLight authModelLight = new AuthModelLight
                 *                      {
                 *                              Desc = "Pending Registration...",
                 *      PersonId = personRegisterModel.ObjectId,
                 *                              EmailAddress = personRegisterModel.Email,
                 *                              Password = null,
                 *                              SessionKey = null
                 *                      };
                 *
                 *                      return authModelLight;
                 *              }
                 */

                else
                {
                    errorInfo = ApplicationConfiguration.RegisterEmailDuplicate;
                }

                return(new AuthModelLight()
                {
                    Desc = errorInfo,
                    PersonId = 0,
                    EmailAddress = personRegisterModel.PerEmailAddress,
                    Password = null,
                    SessionKey = null
                });
            }
            catch (Exception e)
            {
                return(new AuthModelLight()
                {
                    Desc = e.Message,
                    PersonId = 0,
                    EmailAddress = personRegisterModel.PerEmailAddress,
                    Password = null,
                    SessionKey = null
                });
            }
        }