Example #1
0
        public async Task <IActionResult> UpdateRH([FromBody] Responsable_RH model)
        {
            Responsable_RH responsable_RH = (Responsable_RH)await userManagerRH.FindByEmailAsync(model.Email);

            responsable_RH.mdp  = model.mdp;
            responsable_RH.code = model.code;
            var token = await userManagerRH.GeneratePasswordResetTokenAsync(responsable_RH);

            await userManagerRH.ResetPasswordAsync(responsable_RH, token, model.mdp);

            var result = await userManagerRH.UpdateAsync(responsable_RH);

            if (!result.Succeeded)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new Response {
                    message = "Error has been occured !", status = "Error 500 !!"
                }));
            }
            return(Ok(new Response {
                message = "User succefully added !", status = "success 200 "
            }));
        }
Example #2
0
        public async Task <IActionResult> LoginRH([FromBody] Responsable_RH model)
        {
            var userRH = await userManagerRH.FindByEmailAsync(model.Email);

            if (userRH != null && await userManagerRH.CheckPasswordAsync(userRH, model.mdp))
            {
                var userRoles = await userManagerRH.GetRolesAsync(userRH);

                var authClaims = new List <Claim>
                {
                    new Claim(ClaimTypes.Name, userRH.Email),
                    new Claim(System.IdentityModel.Tokens.Jwt.JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString())
                };
                foreach (var userRole in userRoles)
                {
                    authClaims.Add(new Claim(ClaimTypes.Role, userRole));
                }
                var authSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["JWT:Secret"]));
                var email          = "";
                var token          = new JwtSecurityToken(
                    issuer: _configuration["JWT:ValidIssuer"],
                    audience: _configuration["JWT:ValidAudience"],
                    expires: DateTime.Now.AddHours(10),
                    claims: authClaims,
                    signingCredentials: new SigningCredentials(authSigningKey, SecurityAlgorithms.HmacSha256)
                    );
                return(Ok(new
                {
                    token = new JwtSecurityTokenHandler().WriteToken(token),
                    userRH = userRH
                }));
            }
            else
            {
                return(Unauthorized());
            }
        }
Example #3
0
        public async Task <IActionResult> RegisterRH([FromBody] Responsable_RH model)
        {
            var userExist = await userManagerRH.FindByEmailAsync(model.Email);

            var userbyusername = await userManagerRH.FindByNameAsync(model.UserName);

            Console.Write("VARIABLE A AFFFICHER !!!!!!!");
            Responsable_RH responsable_RH = new Responsable_RH
            {
                Email         = model.Email,
                SecurityStamp = Guid.NewGuid().ToString(),
                UserName      = model.UserName,
                mdp           = model.mdp,
            };

            var result = await userManagerRH.CreateAsync(responsable_RH, model.mdp);

            bool x = await roleManager.RoleExistsAsync("Admin");

            if (!x)
            {
                var role = new IdentityRole();
                role.Name = "Admin";
                await roleManager.CreateAsync(role);
            }
            var result1 = await userManager.AddToRoleAsync(responsable_RH, "Admin");

            if (!result.Succeeded)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new Response {
                    message = "Error has been occured !", status = "Error 500 !!"
                }));
            }
            return(Ok(new Response {
                message = "User succefully added !", status = "success 200 "
            }));
        }