コード例 #1
0
        public BankAccount AddSavingsAccount(UserFilter userFilter, BankAccount bankAccount)
        {
            BankAccount res     = null;
            var         details = _UserCollection.Get(userFilter);

            if (details.Any())
            {
                var detail = details.FirstOrDefault();

                if (detail.SavingsAccounts.FirstOrDefault(x => x.Name == bankAccount.Name) != null)
                {
                    _Setting.Message.SetMessage("Duplicate name of bank account!");
                }
                else
                {
                    bankAccount.Id  = Guid.NewGuid();
                    userFilter.Name = null;
                    userFilter.Id   = detail.Id;
                    var countModified = _UserCollection.AddSavingsAccount(userFilter, bankAccount);
                    if (countModified > 0)
                    {
                        res = bankAccount;
                    }
                }
            }

            return(bankAccount);
        }
コード例 #2
0
        public Employee Add(Employee employee)
        {
            string randomPass = _Context.MakeOTP(8);

            employee.Password = randomPass;
            Employee res = null;

            while (true)
            {
                employee.Code = _Context.MakeOTP(10, isAllDigits: true);
                if (!_UserCollection.Get(new UserFilter()
                {
                    AccountNumber = employee.Code
                }).Any())
                {
                    break;
                }
            }
            var user = new User();

            user.AccountNumber = employee.Code;
            user.Address       = employee.Address;
            user.Email         = employee.Email;
            user.Gender        = employee.Gender;
            user.Name          = employee.Name;
            user.Phone         = employee.Phone;
            user.Password      = Encrypting.Bcrypt(employee.Password);
            employee.Username  = string.Concat(employee.Name.Split(' ').Last(), employee.Code);
            user.Role          = 2;


            _UserCollection.Create(user);
            if (user.Id != Guid.Empty)
            {
                employee.Id       = user.Id;
                employee.Password = randomPass;
                res = employee;
            }
            return(res);
        }
コード例 #3
0
        public async Task <User> Login(LoginCredentials credentials)
        {
            var account = await AccountCollection.Get(credentials.Username);

            var passwordsMath = WebrewHasher.Instance.VerifyPasswordMatch(credentials.Password, account.Password, SecuritySettings.PasswordHashSecret, account.Salt);

            if (passwordsMath)
            {
                return(await UserCollection.Get(credentials.Username));
            }

            return(await Task.FromResult <User>(null));
        }
コード例 #4
0
        public DeptReminder AddDeptReminder(Guid userId, DeptReminder deptReminder)
        {
            DeptReminder res        = null;
            var          userDetail = _UserCollection.GetById(userId);

            if (userDetail != null)
            {
                // requestor
                deptReminder.RequestorAccountNumber = userDetail.AccountNumber;
                deptReminder.RequestorId            = userDetail.Id;


                var recipientUsers = _UserCollection.Get(new UserFilter()
                {
                    AccountNumber = deptReminder.RecipientAccountNumber
                });

                if (recipientUsers.Any())
                {
                    var recipientUser = recipientUsers.FirstOrDefault();
                    deptReminder.RecipientId = recipientUser.Id;

                    while (true)
                    {
                        deptReminder.Code = _Context.MakeOTP(15);
                        if (!_DeptReminderCollection.GetMany(new DeptReminderFilter()
                        {
                            Code = deptReminder.Code
                        }).Any())
                        {
                            break;
                        }
                    }

                    _DeptReminderCollection.Create(deptReminder);
                    if (deptReminder.Id != Guid.Empty)
                    {
                        // Send mail
                        var sb = new StringBuilder();
                        sb.AppendFormat($"Dear {recipientUser.Name},");
                        sb.AppendFormat($"<br /><br /><b>Bạn đang được nhắc nợ từ số tài khoản {userDetail.AccountNumber} - {userDetail.Name}.</b>");
                        sb.AppendFormat($"<br /><br /><b>Vui lòng đăng nhập vào hệ thống để xem chi tiết.</b>");
                        sb.AppendFormat($"<br /><br /><b>Nếu yêu cầu không phải của bạn, vui lòng bỏ qua mail này.</b>");

                        if (_Context.SendMail("Thông báo nhắc nợ", sb.ToString(), recipientUser.Email, recipientUser.Name))
                        {
                            res = deptReminder;
                        }
                    }
                }

                //var lstLinkingBank = _LinkingBankCollection.Get(new LinkingBankFilter() { Code = _Setting.BankCode });
                //if (lstLinkingBank.Any())
                //{
                //    deptReminder.Requestor.LinkingBankId = lstLinkingBank.FirstOrDefault().Id;

                //    // check recipient
                //    var recipientLinkingBank = _LinkingBankCollection.GetById(deptReminder.Recipient.LinkingBankId);
                //    if (recipientLinkingBank != null)
                //    {
                //        if (recipientLinkingBank.Code != _Setting.BankCode) // other bank
                //        {
                //            /*TODO*/
                //            //// get user from linking bank
                //        }
                //        else // same bank
                //        {

                //        }
                //    }
                //}
            }
            return(res);
        }
コード例 #5
0
        public bool ConfirmForgetting(Guid id, string email, string otp)
        {
            var res = false;

            var details = _UserCollection.Get(new UserFilter()
            {
                Email = email
            });

            if (details != null && details.Any())
            {
                var detail = details.FirstOrDefault();
                // Get chi tiết giao dịch
                var transactions = _TransactionCollection.GetMany(new TransactionFilter()
                {
                    Id = id, ReferenceId = detail.Id, Type = 2
                });
                if (transactions.Any())
                {
                    var transaction = transactions.FirstOrDefault();
                    // Check Otp
                    if (transaction.Otp == otp)
                    {
                        // Check hết hạn
                        var now = DateTime.Now;
                        if (now <= transaction.ExpireTime && now >= transaction.CreateTime)
                        {
                            // Update mật khẩu
                            using (var sessionTask = _MongoDBClient.StartSessionAsync())
                            {
                                var session = sessionTask.Result;
                                session.StartTransaction();
                                try
                                {
                                    // Create mật khẩu mới
                                    string pass = _Context.MakeOTP(8);

                                    if (_UserCollection.ChangePassword(new UserFilter()
                                    {
                                        Id = detail.Id
                                    }, Encrypting.Bcrypt(pass)) > 0)
                                    {
                                        // Update giao dịch
                                        transaction.ConfirmTime = DateTime.Now;

                                        if (_TransactionCollection.Replace(transaction) > 0)
                                        {
                                            // Send mail
                                            var sb = new StringBuilder();
                                            sb.AppendFormat($"Dear {detail.Name},");
                                            sb.AppendFormat("<br /><br /><b>Yêu cầu quên mật khẩu của bạn đã thực hiện thành công, mật khẩu mới của bạn là:</b>");
                                            sb.AppendFormat($"<br /><br /><b>{pass}</b>");
                                            sb.AppendFormat($"<br /><br /><b>Vui lòng đăng nhập vào hệ thống để kiểm tra.</b>");
                                            sb.AppendFormat($"<br /><br /><b>Nếu yêu cầu không phải của bạn, vui lòng bỏ qua mail này.</b>");

                                            if (_Context.SendMail("Yêu cầu quên mật khẩu", sb.ToString(), detail.Email, detail.Name))
                                            {
                                                res = true;
                                            }
                                            else
                                            {
                                                _Setting.Message.SetMessage("Gửi mail thất bại!");
                                            }
                                        }
                                        else
                                        {
                                            _Setting.Message.SetMessage("Không thể cập nhật thông tin giao dịch!");
                                        }
                                    }
                                    else
                                    {
                                        _Setting.Message.SetMessage("Không thể cập nhật thông tin mật khẩu!");
                                    }

                                    if (res)
                                    {
                                        session.CommitTransactionAsync();
                                    }
                                    else
                                    {
                                        session.AbortTransactionAsync();
                                    }
                                }
                                catch (Exception ex)
                                {
                                    session.AbortTransactionAsync();
                                    throw ex;
                                    throw;
                                }
                            }
                        }
                        else
                        {
                            _Setting.Message.SetMessage("Phiên giao dịch đã hết hạn!");
                        }
                    }
                    else
                    {
                        _Setting.Message.SetMessage("Mã OTP không đúng!");
                    }
                }
                else
                {
                    _Setting.Message.SetMessage("Không tìm thấy thông tin giao dịch!");
                }
            }
            else
            {
                _Setting.Message.SetMessage("Không tìm thấy thông tin người dùng!");
            }

            return(res);
        }