Exemple #1
0
        public async Task <IActionResult> Create([Bind("ItrCode,HospitalId,RegNo,PatientName,PatientFatherName,Age,Sex,Address,MaritalStatus,RefDate,RefTime")] GbvCase gbvCase)
        {
            if (ModelState.IsValid)
            {
                gbvCase.PatientName       = _crypto.Encrypt(gbvCase.PatientName);
                gbvCase.PatientFatherName = _crypto.Encrypt(gbvCase.PatientFatherName);
                gbvCase.GbvCaseId         = Guid.NewGuid();
                gbvCase.UserName          = User.Identity.Name;
                gbvCase.IncCode           = String.Format("{0}-{1}", gbvCase.HospitalId, gbvCase.RegNo);
                gbvCase.InsertDate        = DateTime.Now;
                gbvCase.LastUpdate        = DateTime.Now;
                _context.Add(gbvCase);
                var consent = new Consent();
                consent.GbvCaseId = gbvCase.GbvCaseId;
                _context.Add(consent);
                var reg = new Registration();
                reg.GbvCaseId = gbvCase.GbvCaseId;
                _context.Add(reg);
                var intake = new IntakeInfo();
                intake.GbvCaseId = gbvCase.GbvCaseId;
                _context.Add(intake);
                var auth = new Authorization();
                auth.GbvCaseId = gbvCase.GbvCaseId;
                _context.Add(auth);
                await _context.SaveChangesAsync();

                return(RedirectToAction("edit", "consents", new { id = gbvCase.GbvCaseId }));
            }
            var facilities = _context.FacilityInfo.Where(m => m.User.Equals(User.Identity.Name)).ToList();

            ViewData["HospitalId"] = new SelectList(facilities, "FacilityId", "FacilityName", gbvCase.HospitalId);
            return(View(gbvCase));
        }
Exemple #2
0
        public async Task <IActionResult> OnPost()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Error: Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }

            if (Input.Enable)
            {
                if (Input.Enable && Input.ApiKey.IsNullOrWhiteSpace())
                {
                    ModelState.AddModelError("ApiKey", "Api Key is required.");
                }

                if (Input.Enable && Input.EncryptionKey.IsNullOrWhiteSpace())
                {
                    ModelState.AddModelError("EncryptionKey", "Encryption Key is required.");
                }

                if (!ModelState.IsValid)
                {
                    StatusMessage = "Error: Please review the errors below.";
                    return(Page());
                }

                var encryptedApiKey        = Input.HiddenEncryptedApiKey;
                var encryptedEncryptionKey = Input.HiddenEncryptedEncryptionKey;

                if (Input.HiddenEncryptedApiKey != Input.ApiKey)
                {
                    encryptedApiKey = _cipherService.Encrypt(Input.ApiKey);
                }

                if (Input.HiddenEncryptedEncryptionKey != Input.EncryptionKey)
                {
                    encryptedEncryptionKey = _cipherService.Encrypt(Input.EncryptionKey);
                }

                var pushBulletSettings = new PushBulletSettings()
                {
                    ApiKey        = encryptedApiKey,
                    EncryptionKey = encryptedEncryptionKey
                };

                var pushBulletSettingsString = JsonConvert.SerializeObject(pushBulletSettings);
                var success = await _pushBulletAppService.AddOrUpdatePushBulletSettings(user.Id, pushBulletSettingsString);

                StatusMessage = success ? "Your PushBullet Settings have been encrypted and updated!" : "Error: Unable to save your settings at this time.";
            }
            else
            {
                var success = await _pushBulletAppService.RemovePushBulletService(user.Id);

                StatusMessage = success ? "Your PushBullet integration has been removed." : "Error: Unable to remove PushBullet integration at this time.";
            }

            return(RedirectToPage());
        }
        private void SendValidationMail(User user)
        {
            var host = $"{Request.Scheme}://{Request.Host}";
            var id   = _cipherService.Encrypt(user.id.ToString());
            var body = "Click the following link to start using your account and fill your application.";

            body += $"<br><a href=\"{host}/validate/{id}\">Click here to activate</a>";
            _mailHelper.SendMail(_configuration.GetValue <string>("appSettings:mail:from"), user.email, "Activate your account", body,
                                 _configuration.GetValue <string>("appSettings.registrationMailCc"));
        }
Exemple #4
0
        private static List <User> Users()
        {
            return(new List <User>
            {
                new User
                {
                    Id = Guid.NewGuid(),
                    Name = "filu34",
                    Email = "*****@*****.**",

                    Password = _cipherService.Encrypt("Admin123"),
                    Salt = BCrypt.Net.BCrypt.GenerateSalt(30),
                    CreationDate = DateTime.Now,
                    IsActive = true,
                },
                new User
                {
                    Id = Guid.NewGuid(),
                    Name = "ejdrian313",
                    Email = "*****@*****.**",

                    Password = _cipherService.Encrypt("12345678"),
                    Salt = BCrypt.Net.BCrypt.GenerateSalt(30),
                    CreationDate = DateTime.Now,
                    IsActive = true,
                },
                new User
                {
                    Id = Guid.NewGuid(),
                    Name = "Huo",
                    Email = "*****@*****.**",

                    Password = _cipherService.Encrypt("Admin123"),
                    Salt = BCrypt.Net.BCrypt.GenerateSalt(30),
                    CreationDate = DateTime.Now,
                    IsActive = true,
                },
                new User
                {
                    Id = Guid.NewGuid(),
                    Name = "Buk",
                    Email = "*****@*****.**",

                    Password = _cipherService.Encrypt("Admin123"),
                    Salt = BCrypt.Net.BCrypt.GenerateSalt(30),
                    CreationDate = DateTime.Now,
                    IsActive = true,
                },
            });
        }
Exemple #5
0
        public UserSignup Signup(Entities.User user)
        {
            var users      = _FocusDbContext.Users;
            var userSignup = new UserSignup();

            if (users.SingleOrDefault(u => u.Name == user.Name) != null)
            {
                userSignup.message = "Name already exists!";
            }
            else
            {
                var dbNewUser = new Entities.User()
                {
                    Name     = user.Name,
                    Password = _cipherService.Encrypt(user.Password),
                    Email    = user.Email,
                    Avatar   = ""
                };

                _FocusDbContext.Add(dbNewUser);
                _FocusDbContext.SaveChanges();

                userSignup.user = dbNewUser;
            }

            return(userSignup);
        }
Exemple #6
0
        public async Task <IActionResult> CreateUser(UserDTO user)
        {
            if (user == null)
            {
                return(BadRequest(Utils.GetResponse("EmptyUser", "The user is null")));
            }

            ApplicationUser appUser = new ApplicationUser
            {
                UserName  = user.Email,
                Email     = user.Email,
                FirstName = user.FirstName,
                LastName  = user.LastName,
                Verified  = user.Verified,
                County    = user.County,
                Password  = _cipherService.Encrypt(user.Password)
            };

            var result = await _userManager.CreateAsync(appUser, user.Password);

            if (!result.Succeeded)
            {
                return(BadRequest(Utils.GetResponseByErrorList(result.Errors)));
            }

            string code = await _userManager.GenerateEmailConfirmationTokenAsync(appUser);

            code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));

            Utils.SendEmail(appUser.Email, code);

            var token = BuildToken(user.Email);

            return(Ok(Utils.GetResponse("Token", token)));
        }
Exemple #7
0
        public async Task <string> CreatePasteAsync(string text, string key)
        {
            var encryptedText = _cipherService.Encrypt(text, key);

            var slug = string.Empty;

            for (var length = 2; length < 100; length++)
            {
                slug = SlugGenerator.Generate(length);
                if (!await _context.Pastes.AnyAsync(s => s.Slug == slug))
                {
                    break;
                }
            }

            await _context.Pastes.AddAsync(new Paste
            {
                Slug          = slug,
                EncryptedText = encryptedText
            });

            await _context.SaveChangesAsync();

            return(slug);
        }
        public async Task <GenericResult <UserDto> > AddNewUser(NewUserDto newUserDto)
        {
            try
            {
                if (!await _peopleService.IsPersonExists(newUserDto.FKPersonID))
                {
                    return(GenericResult <UserDto> .UserSafeError("There is no person info with given id"));
                }


                var newUser = await _userRepo.InsertAsync(new User
                {
                    FKPersonID   = newUserDto.FKPersonID,
                    Email        = newUserDto.Email,
                    UserName     = newUserDto.UserName,
                    PasswordHash = _cipherService.Encrypt(newUserDto.Password),
                });

                return(GenericResult <UserDto> .Success(_mapper.Map <UserDto>(newUser)));
            }
            catch (Exception e)
            {
                return(GenericResult <UserDto> .Error(e));
            }
        }
        public UserSignup Signup(Models.User user)
        {
            var        verifyUserEmail = _loginsValidation.verifyUserEmail(user.Email);
            UserSignup userSignup      = new UserSignup()
            {
                message = verifyUserEmail.message
            };

            if (!verifyUserEmail.userEmailCorrect)
            {
                userSignup.message = verifyUserEmail.message;
            }
            else
            {
                var dbNewUser = new Entities.User()
                {
                    FirstName = user.FirstName,
                    LastName  = user.LastName,
                    Email     = user.Email,
                    Password  = _cipherService.Encrypt(user.Password)
                };

                _ffsaDbContext.Add(dbNewUser);
                _ffsaDbContext.SaveChanges();

                _emailsService.SendRegistrationConfirmationEmail(user.FirstName, user.Email, user.Password);

                userSignup.User = dbNewUser;
            }

            return(userSignup);
        }
Exemple #10
0
        public IActionResult OnGet()
        {
            string key = _config.GetSection("PayPal").GetSection("ClientId").Value;

            ClientId = _chipherService.Encrypt(key);

            return(Page());
        }
Exemple #11
0
        public async Task SaveCredential(Credential credential, CancellationToken cancellationToken = default)
        {
            if (_settings == null)
            {
                await ParseSettings(cancellationToken);
            }

            try
            {
                _logger.LogInformation($"Saving credential...");

                var creds = await GetCredential(credential.Name, cancellationToken);

                if (creds == null)
                {
                    _logger.LogDebug($"Credential with the name: '{credential.Name}' was not found, appending to file");

                    var encryptedCredentials = new Credential
                    {
                        Name     = credential.Name,
                        Domain   = credential.Domain,
                        UserName = credential.UserName,
                        Password = _cipherService.Encrypt(credential.Password),
                    };

                    _settings.Credentials.Add(encryptedCredentials);
                }
                else
                {
                    _logger.LogDebug($"Credential with the name: '{credential.Name}' was found. Updating the file");
                    creds.Domain   = credential.Domain;
                    creds.UserName = credential.UserName;
                    creds.Password = _cipherService.Encrypt(credential.Password);
                }

                await _fileManager.WriteSettingsFile(_settings, cancellationToken);

                _logger.LogInformation($"Credential stored");
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Error saving credentials");
                throw;
            }
        }
        public void SetCookie(string key, string value, DateTime expiration)
        {
            var cookie = new HttpCookie(key)
            {
                Value   = _cipherService.Encrypt <DESCryptoServiceProvider>(value, _appKey, _appSalt),
                Expires = expiration
            };

            HttpContext.Current.Request.Cookies.Add(cookie);
            HttpContext.Current.Response.Cookies.Add(cookie);
        }
        public async Task <Unit> Handle(RegisterCustomerCommand request, CancellationToken cancellationToken)
        {
            var hashedIdentity = _cipherService.Encrypt(request.IdentityNumber);

            HashService.CreatePasswordHash(request.Password, out byte[] passwordHash, out byte[] passwordSalt);
            var customter = new Customer(request.FirstName, request.LastName, request.Email, hashedIdentity,
                                         request.Address, _customerUniqunessChecker, passwordSalt, passwordHash);

            await _customerRepository.AddAsync(customter, cancellationToken);

            return(Unit.Task.Result);
        }
Exemple #14
0
        public async Task <IActionResult> Post([FromBody] UserCreateViewModel model)
        {
            if (await _db.User.AnyAsync(x => x.Mobile == model.Mobile))
            {
                throw new MessageException("账号已经存在");
            }
            var securitySeed = Guid.NewGuid().ToString();
            var entity       = Mapper.Map <UserCreateViewModel, User>(model);

            entity.SecuritySeed = securitySeed;
            entity.Password     = _cipher.Encrypt(model.Password, securitySeed);
            entity.UserRoleRel  = new List <UserRoleRel>()
            {
                new UserRoleRel {
                    RoleId = model.RoleId,
                    UserId = entity.Id,
                }
            };
            _db.Add(entity);
            await _db.SaveChangesAsync();

            return(entity.ToFormatJson());
        }
        public EncryptedMessage(
            string topicName,
            string routingKey,
            string sourceServiceName,
            IMessage message,
            ICipherService cipherService)
        {
            Id = Guid.NewGuid();
            ContentTypeName = message.GetType().FullName;

            var serializedMessage = JsonConvert.SerializeObject(message);

            Body = cipherService.Encrypt(serializedMessage);
            SourceServiceName = sourceServiceName;
            TopicName         = topicName;
            RoutingKey        = routingKey;
        }
Exemple #16
0
        public async Task <IActionResult> Post([FromBody] LoginViewModel model)
        {
            var user = await _db.User.FirstOrDefaultAsync(x => x.Code == model.Account);

            if (null == user)
            {
                throw new MessageException("账号不存在");
            }
            if ((int)user.AccountStatus >= (int)EAccountStatus.冻结)
            {
                throw new MessageException("账号状态异常,无法使用");
            }
            if (user.Password != _cipher.Encrypt(model.Password, user.SecuritySeed))
            {
                throw new MessageException("账号密码错误");
            }
            return(CreateJwtToken(user).ToFormatJson());
        }
Exemple #17
0
        private static async Task <HttpContent> EncryptRequestContent(HttpRequestMessage request, ICipherService aesService)
        {
            if (request.Content == null)
            {
                return(request.Content);
            }

            var sourceContentStr = await request.Content.ReadAsStringAsync();

            if (string.IsNullOrWhiteSpace(sourceContentStr))
            {
                return(request.Content);
            }

            //Save Original ContentType
            var sourceContentType = request.Content.Headers.ContentType;

            var encryptContentStr = aesService.Encrypt(sourceContentStr);
            var encryptContent    = new StringContent(encryptContentStr);

            encryptContent.Headers.ContentType = sourceContentType;

            return(encryptContent);
        }
 public string Encrypt(string password)
 {
     return(_cipherService.Encrypt(password));
 }