public async Task <IActionResult> GetMessage(long id) { var message = await messageService.GetMessageById(id); if (message != null) { return(JsonResponseStatus.Success(message)); } return(JsonResponseStatus.NotFound()); }
public async Task <IActionResult> ActivateAccount(string id) { var user = await _userServices.GetUserByEmailActiveCode(id); if (user != null) { _userServices.ActiveUser(user); return(JsonResponseStatus.Success(new { message = $"{user.FirstName} عزیز خوش آمدید!" })); } return(JsonResponseStatus.NotFound()); }
public async Task <IActionResult> ActivateAccount(string id) { var user = await userService.GetUserByEmailActiveCode(id); if (user != null) { userService.ActivateUser(user); return(JsonResponseStatus.Success()); } return(JsonResponseStatus.NotFound()); }
public async Task <IActionResult> Login([FromBody] LoginUserDTO login) { if (ModelState.IsValid) { var res = await userService.LoginUser(login); switch (res) { case LoginUserResult.IncorrectData: return(JsonResponseStatus.NotFound(new { message = "حسابی با این مشخصات وجود ندارد" })); case LoginUserResult.NotActivated: return(JsonResponseStatus.Error(new { message = "حساب کاربری شما فعال نشده است" })); case LoginUserResult.Success: var user = await userService.GetUserByEmail(login.Email); var userRole = await userService.GetUserRoleById(user.Id); var secretKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("JupiterJwtBearer")); var signinCredentials = new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha256); var tokenOptions = new JwtSecurityToken( issuer: "https://localhost:5001", claims: new List <Claim> { new Claim(ClaimTypes.Name, user.Email), new Claim(ClaimTypes.Role, userRole), new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()) }, expires: DateTime.Now.AddDays(30), signingCredentials: signinCredentials ); var tokenString = new JwtSecurityTokenHandler().WriteToken(tokenOptions); return(JsonResponseStatus.Success(new { token = tokenString, expireTime = 30, firstName = user.FirstName, lastName = user.LastName, userId = user.Id, avatar = user.Avatar, role = userRole, email = user.Email, gender = user.Gender, })); } } return(JsonResponseStatus.Error()); }
public async Task <IActionResult> GetProduct(long id) { var product = await productService.GetProductById(id); var productGalleries = await productService.GetProductActiveGalleries(id); if (product != null) { return(JsonResponseStatus.Success(new { product = product, galleries = productGalleries })); } return(JsonResponseStatus.NotFound()); }
public async Task <IActionResult> AddAdminToOrganization([FromBody] RegisterUserDTO user) { var response = await _organizationService.AddAdminToOrganization(user); switch (response) { case RegisterResponse.Exist: return(JsonResponseStatus.NotFound(new { message = "User Exixst" })); case RegisterResponse.Success: return(JsonResponseStatus.Success()); } return(JsonResponseStatus.Error()); }
public async Task <IActionResult> ActiveUser(string id) { if (ModelState.IsValid) { var user = await userService.GetUserByActivatedCode(id); if (user != null) { await userService.ActivatedCode(user); return(JsonResponseStatus.Success()); } } return(JsonResponseStatus.NotFound()); }
public async Task <IActionResult> AddProductComponent([FromBody] AddProductCommentDTO comment) { if (!User.Identity.IsAuthenticated) { return(JsonResponseStatus.Error(new { message = "لطفا ابتدا وارد سایت شوید" })); } if (!await productService.IsExistsProductById(comment.ProductId)) { return(JsonResponseStatus.NotFound()); } var userId = User.GetUserId(); var res = await productService.AddProductComment(comment, userId); return(JsonResponseStatus.Success(res)); }
public async Task <IActionResult> Login([FromBody] LoginUserDTO loginUser) { if (!ModelState.IsValid) { return(JsonResponseStatus.Error()); } var Login = await _userService.LoginUser(loginUser); switch (Login) { case LoginResponse.Exist: return(JsonResponseStatus.NotFound(new { status = "El Email Introducido no existe" })); case LoginResponse.NotActive: return(JsonResponseStatus.Error(new { status = "La cuenta no esta activo" })); case LoginResponse.Success: var user = await _userService.getUserByEmailAddress(loginUser.Email); var secretKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("RKL158e82a5-4899-4a57-93e2-a63599c5da59")); var signninCredentials = new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha256); var tokenOptions = new JwtSecurityToken( issuer: "https://localhost:44399", claims: new List <Claim> { new Claim(ClaimTypes.Name, user.Email), new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()) }, expires: DateTime.Now.AddDays(30), signingCredentials: signninCredentials ); var tokenString = new JwtSecurityTokenHandler().WriteToken(tokenOptions); user.Token = tokenString; user.ExpireTime = 30; return(JsonResponseStatus.Success(user)); } return(JsonResponseStatus.Error()); }
public async Task <IActionResult> GetProduct(long id) { var product = await _productService.GetProductById(id); #region Product Galleries var productGalleries = await _productService.GetProductActiveGalleries(id); #endregion #region Product Related var relatedProduct = await _productService.GetProductRelatedProduct(id); #endregion if (product != null) { return(JsonResponseStatus.Success(new { product = product, galleries = productGalleries, relatedProduct = relatedProduct })); } return(JsonResponseStatus.NotFound()); }
public async Task <IActionResult> Login([FromBody] LoginUserDTO login) { if (ModelState.IsValid) { var res = await _userServices.LoginUser(login); switch (res) { case LoginUserResult.IncorrectData: return(JsonResponseStatus.NotFound(new { message = "کاربری با مشخصات وارد شده یافت نشد" })); case LoginUserResult.NotAdmin: return(JsonResponseStatus.NotFound(new { message = "شما به این بخش دسترسی ندارید" })); case LoginUserResult.NotActivated: return(JsonResponseStatus.Error(new { message = "حساب کاربری شما فعال نشده است" })); case LoginUserResult.Success: var user = await _userServices.GetUserByEmail(login.Email); var secretKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("AngularEShopJwtBearer")); var signinCredential = new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha256); var tokenOptions = new JwtSecurityToken( issuer: "https://localhost:44302", claims: new List <Claim> { new Claim(ClaimTypes.Name, user.Email), new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()) }, expires: DateTime.Now.AddDays(30), signingCredentials: signinCredential ); var tokenString = new JwtSecurityTokenHandler().WriteToken(tokenOptions); return(JsonResponseStatus.Success(new { token = tokenString, expireTime = 30, firstName = user.FirstName, lastName = user.LastName, userId = user.Id, address = user.Address, message = $"{user.FirstName + " " + user.LastName} عزیز خوش آمدید" })); } } return(JsonResponseStatus.Error()); }