コード例 #1
0
ファイル: UserBLL.cs プロジェクト: ezetrivium/MUSICGO
        public override UserViewModel GetById(Guid id)
        {
            try
            {
                PermissionsBLL permissionBLL = new PermissionsBLL();
                UserBE         entity;
                entity             = this.Dal.GetById(id);
                entity.Permissions = permissionBLL.GetUserPermission(entity);

                List <PermissionViewModel> pervmList = new List <PermissionViewModel>();

                permissionBLL.CastPermissions(entity.Permissions, pervmList);

                UserViewModel uvm = Mapper.Map <UserBE, UserViewModel>(entity);

                uvm.Permissions = pervmList;



                var file = FileUtils.GetImageBytes(FileUtils.GetRepoImagePath(uvm.ImgKey));
                uvm.ImageBase64 = "data:image/jpg;base64," + Convert.ToBase64String(file);


                return(uvm);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #2
0
ファイル: UserBLL.cs プロジェクト: ezetrivium/MUSICGO
        public void UpdatePassword(RecoverPasswordViewModel viewModel)
        {
            try
            {
                if (viewModel.Password == viewModel.ConfirmPassword)
                {
                    PermissionsBLL permissionBLL = new PermissionsBLL();
                    UserDAL        userDAL       = new UserDAL();
                    BinnacleSL     binnacleSL    = new BinnacleSL();
                    UserBE         userBE        = new UserBE();
                    userBE.UserName = viewModel.UserName;
                    userBE          = CheckUserName(userBE);
                    DVVerifier dvvv = new DVVerifier();

                    if (CacheManager.GetWithTimeout("ResetPassword" + userBE.Id.ToString()) != null)
                    {
                        string code = CacheManager.GetWithTimeout("ResetPassword" + userBE.Id.ToString()).ToString();

                        if (code == viewModel.Code)
                        {
                            Encryptor encryptor = new Encryptor();
                            userBE.Password = encryptor.Encrypt(viewModel.Password);

                            userBE.Permissions = permissionBLL.GetUserPermission(userBE);

                            if (userDAL.Update(userBE))
                            {
                                UserDAL userdal = new UserDAL();
                                var     userDVH = userdal.GetDVHEntity(userBE.Id);
                                userDVH.DVH = dvvv.DVHCalculate(userDVH);
                                userdal.SetDVH(userDVH);
                                dvvv.DVCalculate("UserDAL");

                                binnacleSL.AddBinnacle(new BinnacleBE()
                                {
                                    User        = userBE,
                                    Description = "UpdatePassword"
                                });
                            }
                            else
                            {
                                throw new BusinessException(Messages.ErrorUpdatePassword);
                            }
                        }
                        else
                        {
                            throw new Exception();
                        }
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
                else
                {
                    throw new BusinessException(Messages.InvalidUpdatePasswordRequest);
                }
            }
            catch (BusinessException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw new Exception(Messages.Generic_Error);
            }
        }
コード例 #3
0
ファイル: UserBLL.cs プロジェクト: ezetrivium/MUSICGO
        public UserViewModel LogIn(UserViewModel viewModel)
        {
            try
            {
                UserBE         userBE        = Mapper.Map <UserViewModel, UserBE>(viewModel);
                PermissionsBLL permissionBLL = new PermissionsBLL();
                BinnacleSL     binnacleSL    = new BinnacleSL();
                UserBE         userLogin     = new UserBE();
                Encryptor      encryptor     = new Encryptor();
                DVVerifier     dVVerifier    = new DVVerifier();
                UserDAL        userDAL       = new UserDAL();
                userLogin = CheckUserName(userBE);
                if (userLogin.Id != Guid.Empty)
                {
                    if (encryptor.CheckEncryption(encryptor.Encrypt(viewModel.Password), userLogin.Password))
                    {
                        if (userLogin.Contract != null && userLogin.Contract.ExpirationDate < DateTime.Now)
                        {
                            userDAL.DeleteContract(userLogin.Id);
                            userLogin.Contract = null;
                        }

                        userLogin.Permissions = permissionBLL.GetUserPermission(userLogin);

                        if (VerifyLoginPermission(userLogin.Permissions))
                        {
                            if (!userLogin.Blocked)
                            {
                                binnacleSL.AddBinnacle(new BinnacleBE()
                                {
                                    User        = userLogin,
                                    Description = "Login",
                                });

                                dVVerifier.DVVerify();

                                var language = new LanguageBLL().GetById(userLogin.Language.Id);


                                userLogin.Language = Mapper.Map <LanguageViewModel, LanguageBE>(language);

                                UserViewModel uservm = Mapper.Map <UserBE, UserViewModel>(userLogin);

                                List <PermissionViewModel> pervmList = new List <PermissionViewModel>();

                                permissionBLL.CastPermissions(userLogin.Permissions, pervmList);

                                uservm.Permissions = pervmList;

                                var file = FileUtils.GetImageBytes(FileUtils.GetRepoImagePath(uservm.ImgKey));
                                uservm.ImageBase64 = "data:image/jpg;base64," + Convert.ToBase64String(file);
                                return(uservm);
                            }
                            else
                            {
                                throw new BusinessException(Messages.User_Blocked);
                            }
                        }
                        else
                        {
                            throw new BusinessException(Messages.LoginNotOk);
                        }
                    }
                    else
                    {
                        var attempsLogin = "******" + userLogin.Id;
                        if (!CacheManager.HasKey(attempsLogin))
                        {
                            CacheManager.SetWithTimeout(attempsLogin, 0, TimeSpan.FromMinutes(30));
                        }

                        CacheManager.Set(attempsLogin, Convert.ToInt32(CacheManager.GetWithTimeout(attempsLogin)) + 1);


                        if (CacheManager.HasKey(attempsLogin) && Convert.ToInt32(CacheManager.GetWithTimeout(attempsLogin)) > 3)
                        {
                            this.Block(userLogin);
                            CacheManager.Remove(attempsLogin);
                            binnacleSL.AddBinnacle(new BinnacleBE()
                            {
                                User        = userLogin,
                                Description = "UserBlocked",
                            });
                            throw new BusinessException(Messages.User_Blocked);
                        }

                        throw new BusinessException(Messages.PasswordNotOk);
                    }
                }
                else
                {
                    throw new BusinessException(Messages.UserNotExists);
                }
            }
            catch (BusinessException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw new Exception(Messages.Generic_Error);
            }
        }