//Khởi tạo GenerateJSONWebToken
        private string GenerateJSONWebToken(Personal_Information userInfo)
        {
            var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Jwt:Key"])); //Khai báo appsetting.Json
            var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);   // ?

            //Yêu cầu
            var claims = new[] //?
            {
                new Claim(JwtRegisteredClaimNames.Sub, userInfo.Account),
                new Claim(JwtRegisteredClaimNames.Sub, userInfo.Pass),
                new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString())
            };

            var token = new JwtSecurityToken //?
                        (
                issuer: _config["Jwt:Issuer"],
                audience: _config["Jwt:Issuer"],
                claims,
                expires: DateTime.Now.AddMinutes(120), //Hạn sử dụng
                signingCredentials: credentials
                        );

            var encodetoken = new JwtSecurityTokenHandler().WriteToken(token); //Tạo token

            return(encodetoken);
        }
Exemple #2
0
 public Profile()
 {
     _School               = new School();
     _College              = new College();
     _University           = new University();
     _Other_Achievements   = new Other_Achievements();
     _Personal_Information = new Personal_Information();
 }
Exemple #3
0
 //Tạo
 public object Create(Personal_Information personalInformation)
 {
     try
     {
         _context.Personal_Information.Add(personalInformation);
         _context.SaveChanges();
         return(personalInformation);
     }
     catch (Exception ex)
     {
         return(ex.StackTrace); //Xuất ra lỗi
     }
 }
        public object CreatePersonal_Information(Personal_InformationReq req)
        {
            //Khởi tạo đối tượng
            Personal_Information personalInformation = new Personal_Information();

            //Gán giá trị
            personalInformation.Account       = req.Account;
            personalInformation.Pass          = req.Pass;
            personalInformation.LastName      = req.LastName;
            personalInformation.FirstName     = req.FirstName;
            personalInformation.DateOfBirth   = req.DateOfBirth;
            personalInformation.Gender        = req.Gender;
            personalInformation.Address       = req.Address;
            personalInformation.PhoneNumber   = req.PhoneNumber;
            personalInformation.Email         = req.Email;
            personalInformation.AccountTypeID = req.AccountTypeID; //Chỉ chính xác là đối tượng khóa ngoại
            personalInformation.CreatedDate   = req.CreatedDate;
            personalInformation.AccountStatus = req.AccountStatus;
            personalInformation.Note          = req.Note;
            //Truyền giá trị
            return(_rep.Create(personalInformation));
        }