Ejemplo n.º 1
0
        public async Task <IActionResult> login([FromBody] UserRequest user)
        {
            var acount = await _acountService.get(user);

            if (acount == null)
            {
                return(Ok(new BaseResponse(400, "Đăng nhập thất bại. Mời kiểm tra lại thông tin")));
            }
            else
            {
                var role = acount.ObjectRole;
                if (role == "ROLE_ENTERPRISE")
                {
                    String token = _jwtAuthenticationManager.Authenticate(user.Username, user.Password, acount);
                    if (token == null)
                    {
                        return(Ok(new BaseResponse(400, "Đăng nhập thất bại. Mời kiểm tra lại thông tin")));
                    }
                    else
                    {
                        return(Ok(new TokenResult(token)));
                    }
                }
                return(Ok(new BaseResponse(400, "Đăng nhập thất bại. Mời kiểm tra lại thông tin")));
            }
        }
Ejemplo n.º 2
0
        public async Task <int> createEntAcount(EntRegisterInfo entRegisterInfo)
        {
            var user = new UserRequest()
            {
                Username = entRegisterInfo.Username, Password = entRegisterInfo.Password
            };
            var acount = await _acountService.get(user);

            if (acount != null)
            {
                return(0);
            }
            else
            {
                //var newacc = await _acountService.create(entRegisterInfo.Username, entRegisterInfo.Password, "ROLE_ENTERPRISE");
                var newacc = new Acount()
                {
                    Username   = entRegisterInfo.Username,
                    Password   = entRegisterInfo.Password,
                    ObjectRole = "ROLE_ENTERPRISE"
                };
                _dbContext.Acounts.Add(newacc);
                var ent = new Enterprise()
                {
                    Name     = entRegisterInfo.Name,
                    Email    = entRegisterInfo.Email,
                    Phone    = entRegisterInfo.Phone,
                    Skype    = entRegisterInfo.Skype,
                    Position = entRegisterInfo.Position
                };
                if (entRegisterInfo.Gender == "male")
                {
                    ent.Gender = true;
                }
                else
                {
                    ent.Gender = false;
                }
                _dbContext.Enterprises.Add(ent);
                ent.Acount = newacc;

                var entInfo = new EnterpriseInfo()
                {
                    Company_Name = entRegisterInfo.Company_name,
                    Tax_Code     = entRegisterInfo.Tax_code,
                    Area         = entRegisterInfo.Area,
                    Phone        = entRegisterInfo.Company_phone,
                    Email        = entRegisterInfo.Company_Email,
                    Website      = entRegisterInfo.Website,
                    Scale        = entRegisterInfo.Scale
                };

                _dbContext.EnterpriseInfos.Add(entInfo);
                entInfo.Enterprise = ent;

                return(await _dbContext.SaveChangesAsync());
            }
        }
Ejemplo n.º 3
0
        public async Task <Acount> get()
        {
            UserRequest user = new UserRequest()
            {
                Username = "******", Password = "******"
            };
            var acount = await _acountService.get(user);

            return(acount);
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Authenticate([FromBody] UserRequest user)
        {
            var acount = await _acountService.get(user);

            var token = jwtAuthenticationManager.Authenticate(user.Username, user.Password, acount);

            if (token == null)
            {
                return(Unauthorized());
            }
            return(Ok(token));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> authenticate([FromBody] UserRequest user)
        {
            var acount = await _acountService.get(user);

            String token = _jwtAuthenticationManager.Authenticate(user.Username, user.Password, acount);

            if (token == null)
            {
                return(Ok(new BaseResponse(400, "Đăng nhập thất bại. Mời kiểm tra lại thông tin")));
            }
            else
            {
                return(Ok(new TokenResult(token)));
            }
        }