public VerifyAccountResult VerifyAccount(string emailAddress, int code)
        {
            var now = DateTime.UtcNow;

            var verificationNumber = (from number in _context.AccountVerificationNumbers
                                      join account in _context.Accounts on number.AccountId equals account.AccountId
                                      where !number.Deleted && number.Number == code && account.EmailAddress == emailAddress
                                      select number).SingleOrDefault();
            var result = new VerifyAccountResult();

            if (verificationNumber == null)
            {
                result.Messages.Add($"{code} is an invalid code.");
                result.Result = false;
            }
            if (verificationNumber != null && (now.Subtract(verificationNumber.Expires).Hours > 1))
            {
                result.Messages.Add($"{code} has expired.");
                result.Result = false;
            }

            if (result.Result)
            {
                //At this point, the account has been verified. The code is valid and is hasn't expired
                var userAccount = _context.Accounts.Single(x => x.EmailAddress == emailAddress);
                userAccount.Verified = true;
                userAccount.Active   = true;
                //Hard delte the verification row to free up the number
                _context.AccountVerificationNumbers.Remove(verificationNumber);

                _context.SaveChanges();
            }

            //Result is true by default. If the checks don't fail, just return default object with no messages
            return(result);
        }
示例#2
0
 public bool VerifyAccount(string login, string passwd, ClientSession session, ref VerifyAccountResult result)
 {
     return(true);
 }
示例#3
0
 public bool VerifyAccount(string login, string passwd, ClientSession session, ref VerifyAccountResult result)
 {
     /*
      * lock ( _lock )
      * {
      *  if( _clients.ContainsKey( login.ToLower() ) )
      *  {
      *      result = VerifyAccountResult.MULTIPLE_CONN_TRY;
      *
      *      return true; // Already Logged In
      *  }
      *
      *  //                if (!Database.Exists("accounts", "Username = '******' AND Password = '******'", login, passwd))
      *  //                {
      *  //                    result = VerifyAccountResult.WRONG_PASSWD;
      *  //
      *  //                    return true;
      *  //                }
      *
      *  dynamic datum = new Datum("accounts");
      *
      *  try
      *  {
      *      datum.Populate( "Username = '******'", login, passwd );
      *  }
      *  catch( RowNotInTableException )
      *  {
      *      //result = VerifyAccountResult.WRONG_PASSWD;
      *      //
      *      //return true;
      *
      *      Database.ExecuteScript( Database.Host, Database.Username, Database.Password, "INSERT INTO {0}.accounts (Username, Password) VALUES ('{1}', '{2}')", Database.Schema, login, passwd );
      *
      *      result = VerifyAccountResult.SUCCESS;
      *
      *      try
      *      {
      *          datum.Populate( "Username = '******'", login, passwd );
      *      }
      *      catch( RowNotInTableException )
      *      {
      *          result = VerifyAccountResult.INVALID_PROTOCOL;
      *
      *          return false;
      *      }
      *  }
      *
      *  if( datum.Password != passwd )
      *  {
      *      result = VerifyAccountResult.WRONG_PASSWD;
      *
      *      return true;
      *  }
      *
      *  session.AccountName = login;
      *  session.Exp0 = datum.Exp0;
      *  session.Exp1 = datum.Exp1;
      *  session.Exp2 = datum.Exp2;
      *  session.GamePoint = datum.GamePoint;
      *  session.AuthLevel = datum.AuthLevel;
      *
      *  foreach( dynamic datumItem in new Datums( "inventory" ).Populate( "OwnerLogin = '******'", login ) )
      *  {
      *      session.Inventory.Add( new ItemInfo() { GoodsID = datumItem.GoodsID, GoodsUID = datumItem.GoodsUID } );
      *  }
      *
      *  foreach( dynamic datumEqp in new Datums( "equipitem" ).Populate( "OwnerLogin = '******'", login ) )
      *  {
      *      int Slot = datumEqp.Slot;
      *      uint GoodsID = datumEqp.GoodsID;
      *
      *      if( Slot >= 0 && Slot < 15 )
      *          session.EquipItems[ 0 ].Add( Slot, GoodsID );
      *      else if( Slot >= 15 && Slot < 30 )
      *          session.EquipItems[ 1 ].Add( Slot - 15, GoodsID );
      *      else if( Slot >= 30 && Slot < 45 )
      *          session.EquipItems[ 2 ].Add( Slot - 30, GoodsID );
      *  }
      *
      *  for( int i = 0; i < session.EquipItems.Length; i++ )
      *  {
      *      for( int j = 0; j < 15; j++ ) // max 15 equips
      *      {
      *          if( !session.EquipItems[ i ].ContainsKey( j ) )
      *          {
      *              session.EquipItems[ i ].Add( j, 0xFFFFFFFF );
      *          }
      *      }
      *  }
      *
      *  _clients.Add( login, session );
      *
      *  result = VerifyAccountResult.SUCCESS;
      *
      *  return true;
      * }
      */
     return(true);
 }