コード例 #1
0
 public bool AddUser(Account account, out string errorMessage)
 {
     errorMessage = string.Empty;
     try
     {
         var exUser = Articles.FindAllAsync(Schemas.User, Query.Property("username").IsEqualTo(account.UserName).ToString(), new[] { "__id" }).Result;
         if (exUser == null || exUser.Count == 0)
         {
             User user = new User();
             user.Set("username", account.UserName);
             user.Set("email", account.Email);
             user.Set("firstname", account.FirstName);
             user.Set("lastname", account.LastName);
             user.Set("password", account.Password);
             var profile = new Article(Schemas.Profile);
             profile.Set("total_points", "1");
             profile.Set("level", "1");
             profile.Set("max_game_limit", AppConfigurations.MaxAllowedGamesPerUser);
             var userProfile = Connection.New(Relations.UserProfile)
                 .FromNewArticle(Schemas.User, user)
                 .ToNewArticle(Schemas.Profile, profile).SaveAsync();
             userProfile.Wait();
             account.Id = user.Id;
             return true;
         }
     }
     catch (Exception ex)
     {
         errorMessage = ex.Message;
         return false;
     }
     errorMessage = "User name already exist!!!";
     return false;
 }
コード例 #2
0
ファイル: Player.cs プロジェクト: TokleMahesh/GOB
 public Player(Account copy)
 {
     this.UserName = copy.UserName;
     this.AccessToken = copy.AccessToken;
     this.Email = copy.Email;
     this.FirstName = copy.FirstName;
     this.LastName = copy.LastName;
     this.Id = copy.Id;
     this.Password = copy.Password;
     this.MaxGameLimit = copy.MaxGameLimit;
     this.Level = copy.Level;
 }
コード例 #3
0
ファイル: ArticleExtensions.cs プロジェクト: TokleMahesh/GOB
 public static Account ToModelAccount(this User user, Article profile)
 {
     if (user == null)
         return null;
     Account account = new Account()
     {
         UserName = user.Get<string>("username"),
         Email = user.Get<string>("email"),
         FirstName = user.Get<string>("firstname"),
         LastName = user.Get<string>("lastname"),
         Id = user.Id
     };
     if (profile != null)
     {
         account.MaxGameLimit = profile.Get<int>("max_game_limit",0);
         account.Level = profile.Get<int>("level",0);
         account.Points = profile.Get<int>("total_points", 0);
     }
     return account;
 }
コード例 #4
0
 public string Login(ref Account account, out string errorMessage)
 {
     string token = string.Empty;
     errorMessage = string.Empty;
     var creds = new UsernamePasswordCredentials(account.UserName, account.Password)
     {
         TimeoutInSeconds = 15*60,
         MaxAttempts = int.MaxValue
     };
     try
     {
         // Authenticate
         var result = creds.AuthenticateAsync().Result;
         if (result != null)
         {
             User loggedInUser = result.LoggedInUser;
             token = result.UserToken;
             var profile = loggedInUser.GetConnectedArticlesAsync(Relations.UserProfile).Result;
             account = loggedInUser.ToModelAccount(profile.SingleOrDefault());
         }
         else
         {
             errorMessage = "Username and password doesnt match!! Retry.";
         }
     }
     catch (Exception ex)
     {
         errorMessage = ex.Message;
     }
     return token;
 }