public async Task <IActionResult> SetProfilePic([FromBody] SetProfilePicModal modal, [FromHeader] JwtBody jwt) { bool succeeded = await picRepository.setProfilePic(jwt.id, modal.picBase64); return(Json(new BaseResponse(succeeded))); }
public async Task <ActionResult> SendBinary([FromBody] SendBinaryRequest req, [FromHeader] JwtBody jwt) { var group = await groupRepo.GetById(req.Title); if (group == null) { return(Json(new BaseResponse(false, "Group does not exist"))); } var sendBinaryModel = new SendBinariesModel() { base64Data = req.base64Data, senderLanguage = jwt.language, recipientIds = group.membersList.Select(m => m.Id).ToList() }; return(RedirectToAction("SendBinaries", "ChatController", new RouteValueDictionary ( new { binariesModel = sendBinaryModel, jwtBody = jwt } ))); }
public JsonResult GetProfilePic([FromHeader] JwtBody jwt) { string path = picRepository.getProfilePicPath(jwt.id); return(Json(new ProfilePicResponse { succeeded = true, picUrl = path })); }
public async Task <JsonResult> UpdateAccount([FromBody] UpdateAccountModal accModal, [FromHeader] JwtBody jwt) { User user = await userRepository.GetById(jwt.id); if (user == null) { return(Json(new BaseResponse(false, "User does not exist"))); } else { if (accModal.displayName != null) { user.displayName = accModal.displayName; } if (accModal.passwordHash != null) { user.passwordHash = accModal.passwordHash; } if (accModal.firebaseToken != null) { user.firebaseToken = accModal.firebaseToken; } if (accModal.fullName != null) { user.fullName = accModal.fullName; } if (accModal.email != null) { user.email = accModal.email; } if (accModal.language != null) { user.language = accModal.language; user.langCode = langCodes.GetCode(user.language); } await userRepository.Save(); string token = tokenService.Issue(new JwtBody { issuedAt = (DateTime.UtcNow.Subtract( new System.DateTime(1970, 1, 1))).TotalSeconds.ToString(), id = user.Id.ToString(), displayName = user.displayName, langCode = user.langCode, translationEngine = accModal.translationEngine }); return(Json(new TokenResponse { succeeded = true, token = token })); } }
public async Task <JsonResult> DeleteAccount([FromHeader] JwtBody jwt) { User u = await userRepository.GetById(jwt.id); if (u == null) { Json(new BaseResponse(false, "User does not exist")); } await userRepository.Delete(u); return(Json(new BaseResponse(true))); }
public async Task <JsonResult> SendMessages([FromBody] SendMessagesModel messageModal, [FromHeader] JwtBody jwtBody) { // filter out users var recipients = await userRepository .GetAll() .Where(u => messageModal.recipientIds.Contains(u.Id.ToString())) .Where(u => CanSendToUser(jwtBody.id, u)) .ToListAsync(); var sender = await userRepository.GetById(jwtBody.id); bool sent = await messagingService.SendMessages(sender, recipients, messageModal.message); return(Json(new BaseResponse(sent, sent ? null : "Not all users received message"))); }
public async Task <JsonResult> UnBlock([FromBody] RecipientModel recipient, [FromHeader] JwtBody jwt) { User user = await userRepository.GetById(jwt.id); if (user == null) { return(Json(new BaseResponse(false, "User does not exist"))); } if (!user.blockedIds.Contains(recipient.recipientId)) { return(Json(new BaseResponse(false, "User not blocked"))); } user.blockedIds.Remove(recipient.recipientId); return(Json(new BaseResponse(true))); }
public async Task <UsersResponse> GetUsers([FromHeader] JwtBody jwtBody) { return(new UsersResponse { Users = userRepository .GetAll() .Select(u => new UserResponse { Id = u.Id, langCode = u.langCode, language = u.language, displayName = u.displayName, fullName = u.fullName, email = u.email, firebaseToken = u.firebaseToken }) .ToList() }); }
public async Task <JsonResult> send([FromBody] SendMessageModel messageModel, [FromHeader] JwtBody jwtBody) { // check if user exsts var pair = await GetUserPair(jwtBody.id, messageModel.recipientId); if (pair.Recipient == null) { return(Json(new BaseResponse(false, "User does not exist"))); } if (!CanSendToUser(jwtBody.id, pair.Recipient)) { return(Json(new BaseResponse(false, "Can not send to user"))); } bool sent = await messagingService .SendMessage(pair.Sender, pair.Recipient, messageModel.message); return(Json(new BaseResponse(sent, sent ? null : "Message not sent"))); }
public async Task <JsonResult> poorTranslation([FromBody] PoorTranslationModel translationModel, [FromHeader] JwtBody jwtBody) { // check if user exsts var pair = await GetUserPair(jwtBody.id, translationModel.recipientId); if (pair.Recipient == null) { return(Json(new BaseResponse(false, "User does not exist"))); } if (!CanSendToUser(jwtBody.id, pair.Recipient)) { return(Json(new BaseResponse(false, "Can not send to user"))); } bool sent = await messagingService.NotifyPoorTranslation(pair.Sender, pair.Recipient, translationModel.message); return(Json(new BaseResponse(sent, sent ? null : "Not all users received message"))); }
public async Task <JsonResult> Block([FromBody] RecipientModel recipient, [FromHeader] JwtBody jwt) { User user = await userRepository.GetById(jwt.id); if (user == null) { return(Json(new BaseResponse(false, "User does not exist"))); } if (user.blockedIds.Contains(recipient.recipientId)) { return(Json(new BaseResponse(false, "User already blocked"))); } user.blockedIds.Add(recipient.recipientId); user.invitations.RemoveAll(i => i.senderId == recipient.recipientId); await userRepository.Save(); return(Json(new BaseResponse(true))); }