public async Task <IActionResult> CompleteRequest(CompleteRequestAddressModel model) { var user = await GetKahlaUser(); var request = await _dbContext.Requests.FindAsync(model.Id); if (request == null) { return(this.Protocal(ErrorType.NotFound, "We can not find target request.")); } if (request.TargetId != user.Id) { return(this.Protocal(ErrorType.Unauthorized, "The target user of this request is not you.")); } if (request.Completed == true) { return(this.Protocal(ErrorType.HasDoneAlready, "The target request is already completed.")); } request.Completed = true; if (model.Accept) { if (await _dbContext.AreFriends(request.CreatorId, request.TargetId)) { await _dbContext.SaveChangesAsync(); return(this.Protocal(ErrorType.RequireAttention, "You two are already friends.")); } _dbContext.AddFriend(request.CreatorId, request.TargetId); await _pusher.FriendAcceptedEvent(request.CreatorId); } await _dbContext.SaveChangesAsync(); return(this.Protocal(ErrorType.Success, "You have successfully completed this request.")); }
public async Task <IActionResult> AuthByPassword(AuthByPasswordAddressModel model) { var pack = await _oauthService.PasswordAuthAsync(Extends.CurrentAppId, model.Email, model.Password); if (pack.Code != ErrorType.Success) { return(this.Protocol(ErrorType.Unauthorized, pack.Message)); } var user = await _authService.AuthApp(new AuthResultAddressModel { code = pack.Value, state = string.Empty }, isPersistent : true); if (!await _dbContext.AreFriends(user.Id, user.Id)) { _dbContext.AddFriend(user.Id, user.Id); await _dbContext.SaveChangesAsync(); } return(Json(new AiurProtocol() { Code = ErrorType.Success, Message = "Auth success." })); }
public async Task <IActionResult> AuthResult(AuthResultAddressModel model) { var user = await _authService.AuthApp(model, isPersistent : true); this.SetClientLang(user.PreferedLanguage); var domain = _appDomains.FirstOrDefault(t => t.Server.ToLower().Trim() == Request.Host.ToString().ToLower().Trim()); if (domain == null) { return(NotFound()); } if (!await _dbContext.AreFriends(user.Id, user.Id)) { _dbContext.AddFriend(user.Id, user.Id); await _dbContext.SaveChangesAsync(); } return(Redirect(domain.Client)); }
private async Task <PrivateConversation> AcceptRequest(Request request, bool accept) { PrivateConversation newConversation = null; request.Completed = true; await semaphoreSlim.WaitAsync(); try { if (accept) { if (await _dbContext.AreFriends(request.CreatorId, request.TargetId)) { await _dbContext.SaveChangesAsync(); throw new AiurAPIModelException(ErrorType.HasSuccessAlready, "You two are already friends."); } newConversation = _dbContext.AddFriend(request.CreatorId, request.TargetId); } await _dbContext.SaveChangesAsync(); } finally { semaphoreSlim.Release(); } await Task.WhenAll( _pusher.FriendsChangedEvent( request.Creator, request, accept, newConversation?.Build(request.CreatorId, _onlineJudger) as PrivateConversation), _pusher.FriendsChangedEvent( request.Target, request, accept, newConversation?.Build(request.TargetId, _onlineJudger) as PrivateConversation)); return(newConversation); }
public async Task <IActionResult> CompleteRequest(CompleteRequestAddressModel model) { var user = await GetKahlaUser(); var request = await _dbContext .Requests .Include(t => t.Creator) .ThenInclude(t => t.HisDevices) .Include(t => t.Target) .ThenInclude(t => t.HisDevices) .SingleOrDefaultAsync(t => t.Id == model.Id); if (request == null) { return(this.Protocol(ErrorType.NotFound, "We can not find target request.")); } if (request.TargetId != user.Id) { return(this.Protocol(ErrorType.Unauthorized, "The target user of this request is not you.")); } if (request.Completed) { return(this.Protocol(ErrorType.HasDoneAlready, "The target request is already completed.")); } request.Completed = true; PrivateConversation newConversation = null; if (model.Accept) { if (await _dbContext.AreFriends(request.CreatorId, request.TargetId)) { await _dbContext.SaveChangesAsync(); return(this.Protocol(ErrorType.RequireAttention, "You two are already friends.")); } newConversation = _dbContext.AddFriend(request.CreatorId, request.TargetId); await _dbContext.SaveChangesAsync(); } else { await _dbContext.SaveChangesAsync(); } await Task.WhenAll( _pusher.FriendsChangedEvent( request.Creator, request, model.Accept, newConversation?.Build(request.CreatorId, _onlineJudger) as PrivateConversation), _pusher.FriendsChangedEvent( request.Target, request, model.Accept, newConversation?.Build(request.TargetId, _onlineJudger) as PrivateConversation) ); return(Json(new AiurValue <int?>(newConversation?.Id) { Code = ErrorType.Success, Message = "You have successfully completed this request." })); }