示例#1
0
        public async Task <IActionResult> QuenMatKhau(QuenMatKhauRequest request)
        {
            int    result          = 0;
            string newPassword     = SendMailService.GenerateString();
            string newHashPassword = BCryptService.HashPassword(newPassword);

            result = await _userService.QuenMatKhau(request.tenDangNhap, request.email, newHashPassword);

            if (result == 1)
            {
                var           subject = "Xác nhận quên mật khẩu";
                StringBuilder body    = new StringBuilder();
                body.AppendFormat("Mật khẩu mới của bạn là: {0}", newPassword);

                try
                {
                    var message = SendMailService.InitEmailMessage(request.email, subject, body.ToString());
                    SendMailService.SendMail(message);
                    return(Ok(result));
                }
                catch (Exception ex)
                {
                    return(StatusCode(500));
                }
            }

            return(NotFound());
        }
示例#2
0
        public async Task <ActionResult <int> > DangKyTaiKhoanKhachHang(DangKyRequest request)
        {
            var result = 0;

            string maTaiKhoan = GenerateMaTaiKhoan(request.Sdt);

            string password     = SendMailService.GenerateString();
            string hashPassword = BCryptService.HashPassword(password);
            string soTaiKhoan   = GenerateSoTaiKhoan(request.Sdt);

            TaiKhoanDangNhapBO taiKhoanDangNhap = new TaiKhoanDangNhapBO();

            taiKhoanDangNhap.MaTaiKhoan     = maTaiKhoan;
            taiKhoanDangNhap.TenDangNhap    = request.TenDangNhap;
            taiKhoanDangNhap.MatKhau        = hashPassword;
            taiKhoanDangNhap.IdLoaiTaiKhoan = 1;

            TaiKhoanKhachHangBO taiKhoanKhachHang = new TaiKhoanKhachHangBO();

            taiKhoanKhachHang.MaTk        = maTaiKhoan;
            taiKhoanKhachHang.Sdt         = request.Sdt;
            taiKhoanKhachHang.Email       = request.Email;
            taiKhoanKhachHang.SoTaiKhoan  = soTaiKhoan;
            taiKhoanKhachHang.TenTaiKhoan = request.HoTen;
            taiKhoanKhachHang.SoDu        = 0;

            var themTaiKhoanResult = _userService.ThemTaiKhoanDangNhap(taiKhoanDangNhap);

            if (themTaiKhoanResult.Result == 1)
            {
                // Send mail after create success
                var           subject = "Đăng ký tài khoản";
                StringBuilder body    = new StringBuilder();
                body.AppendFormat("Mật khẩu của bạn là: {0}", password);
                var message = SendMailService.InitEmailMessage(request.Email, subject, body.ToString());
                SendMailService.SendMail(message);

                result = _userService.ThemThongTinTaiKhoanKhachHang(taiKhoanKhachHang).Result;
                return(result);
            }
            else
            {
                return(StatusCode(500));
            }
        }
示例#3
0
        public async Task <IActionResult> SendMailOTP(string email)
        {
            // Generate OTP
            var otp = SendMailService.GenerateOTP();

            var           subject = "[18HCB Banking] Mã xác nhận";
            StringBuilder body    = new StringBuilder();

            body.AppendFormat("Mã xác nhận của bạn là: {0}", otp);

            try
            {
                var message = SendMailService.InitEmailMessage(email, subject, body.ToString());
                SendMailService.SendMail(message);
                return(Ok(otp));
            } catch (Exception ex)
            {
                return(StatusCode(500));
            }
        }