コード例 #1
0
 public async Task<Sharelinker> CreateNewUser(Sharelinker newUser)
 {
     var collection = Client.GetDatabase("Sharelink").GetCollection<Sharelinker>("Sharelinker");
     await collection.InsertOneAsync(newUser);
     return newUser;
 }
コード例 #2
0
        public async Task<object> Post(string accountId, string accessToken, string nickName, string motto,string region="us")
        {
            var userService = this.UseSharelinkerService().GetSharelinkerService();
            var test = await userService.GetUserOfAccountId(accountId);
            if (test != null)
            {
                Response.StatusCode = (int)HttpStatusCode.Forbidden;
                return "One AccountId Only Regist One Time";
            }
            var tokenService = Startup.ServicesProvider.GetTokenService();
            var userSession = await tokenService.ValidateToGetSessionData(Startup.Appkey, accountId, accessToken);
            if (userSession != null)
            {
                var newUser = new Sharelinker()
                {
                    AccountId = accountId,
                    NickName = nickName,
                    CreateTime = DateTime.UtcNow,
                    NoteName = nickName,
                    Motto = motto
                };

                
                var user = await userService.CreateNewUser(newUser);
                var newUserId = user.Id.ToString();

                #region New User Default Datas
                //Add user self
                await userService.CreateNewLinkWithOtherUser(newUserId, newUserId, new SharelinkerLink.State() { LinkState = (int)SharelinkerLink.LinkState.Linked },nickName);

                //Add SharelinkerCenter
                var centerId = "";
                try
                {
                    centerId = Startup.SharelinkCenters[region];
                }
                catch (Exception)
                {
                    centerId = Startup.SharelinkCenters["us"];
                }
                
                var centerOId = new ObjectId(centerId);
                await userService.CreateNewLinkWithOtherUser(newUserId, centerId, new SharelinkerLink.State() { LinkState = (int)SharelinkerLink.LinkState.Linked }, SharelinkerConstants.SharelinkCenterNickName);

                //Add default share for user
                var shareService = this.UseShareService().GetShareService();
                var initShares = Startup.Configuration.GetSection(string.Format("InitShareThing:{0}:shares",region)).GetChildren();
                var now = 0;
                var shares = from share in initShares
                             select new ShareThing()
                             {
                                 Message = share["message"],
                                 ShareContent = share["content"],
                                 ShareType = share["contentType"],
                                 UserId = centerOId,
                                 Reshareable = true,
                                 ShareTime = DateTime.UtcNow.AddSeconds(now -= 7) //sort by time
                             };
                var defaultShareThings = await shareService.CreateNewSharelinkerDefaultShareThings(shares);
                var shareMails = from s in defaultShareThings
                                 select new ShareThingMail()
                                 {
                                     ShareId = s.Id,
                                     Tags = new string[] { "Broadcast" },
                                     ToSharelinker = newUser.Id,
                                     Time = s.ShareTime
                                 };
                await shareService.InsertMails(shareMails);
                #endregion

                var sessionData = await tokenService.ValidateAccessToken(Startup.Appkey, accountId, accessToken, newUser.Id.ToString());
                return new
                {
                    succeed = true,
                    appToken = sessionData.UserSessionData.AppToken,
                    userId = sessionData.UserSessionData.UserId,
                    apiServer = Startup.APIUrl,
                    fileAPIServer = Startup.FileApiUrl,
                    chicagoServer = string.Format("{0}:{1}", Startup.ChicagoServerAddress, Startup.ChicagoServerPort)
                };
            }
            else
            {
                Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return "Validate Fail,Can't Not Regist New User";
            }
        }