/// <summary>
        /// Creates a MobileToken and inserts it into the database.
        /// </summary>
        /// <param name="token">MobileToken to be created.</param>
        /// <returns>The created MobileToken.</returns>
        public MobileToken Create(MobileToken token)
        {
            var randomToken = GenerateToken();

            //Check if tokens exists
            var exists = true;

            while (exists)
            {
                if (_repo.AsQueryable().Any(x => x.Token.Equals(randomToken)))
                {
                    randomToken = GenerateToken();
                }
                else
                {
                    exists = false;
                }
            }

            token.Token  = randomToken;
            token.Guid   = Guid.NewGuid();
            token.Status = MobileTokenStatus.Created;

            if (token.Status == MobileTokenStatus.Created)
            {
                token.StatusToPresent = "Oprettet";
            }

            if (token.Status == MobileTokenStatus.Activated)
            {
                token.StatusToPresent = "Aktiveret";
            }

            var createdToken = _repo.Insert(token);

            _repo.Save();

            var _dmzTokenRepo = new GenericDmzRepository <Token>(new DmzContext());

            var dmzToken = new Token
            {
                Status      = (int)createdToken.Status,
                GuId        = createdToken.Guid.ToString(),
                TokenString = createdToken.Token,
                ProfileId   = createdToken.PersonId,
            };

            dmzToken = Encryptor.EncryptToken(dmzToken);
            _dmzTokenRepo.Insert(dmzToken);
            _dmzTokenRepo.Save();

            return(createdToken);
        }
示例#2
0
        public AppLogin SyncToDmz(AppLogin appLogin)
        {
            var _dmzAuthRepo = new GenericDmzRepository <UserAuth>(new DmzContext());

            var encryptedLogin = Encryptor.EncryptAppLogin(appLogin);
            var dmzLogin       = new UserAuth
            {
                UserName  = encryptedLogin.UserName,
                GuId      = encryptedLogin.GuId,
                Password  = encryptedLogin.Password,
                ProfileId = encryptedLogin.PersonId,
                Salt      = encryptedLogin.Salt
            };

            _dmzAuthRepo.Insert(dmzLogin);
            _dmzAuthRepo.Save();

            return(encryptedLogin);
        }