RegisteredIp implemented in Account

main
Inga 🏳‍🌈 14 years ago
parent b74fa316b9
commit 5d64016a2b
  1. 2
      Builder/IISMainHandler/build.txt
  2. 11
      Common/dataobjects/Account.cs
  3. 4
      Common/dataobjects/Invite.cs
  4. 2
      IISMainHandler/handlers/request/MigrateAccountHandler.cs
  5. 2
      IISMainHandler/handlers/request/RegisterByInviteHandler.cs

@ -18,6 +18,7 @@ namespace FLocal.Common.dataobjects {
public const string FIELD_PASSWORDHASH = "Password"; public const string FIELD_PASSWORDHASH = "Password";
public const string FIELD_NEEDSMIGRATION = "NeedsMigration"; public const string FIELD_NEEDSMIGRATION = "NeedsMigration";
public const string FIELD_NAME = "Name"; public const string FIELD_NAME = "Name";
public const string FIELD_IPADDRESS = "IpAddress";
public static readonly TableSpec instance = new TableSpec(); public static readonly TableSpec instance = new TableSpec();
public string name { get { return TABLE; } } public string name { get { return TABLE; } }
public string idName { get { return FIELD_ID; } } public string idName { get { return FIELD_ID; } }
@ -158,7 +159,7 @@ namespace FLocal.Common.dataobjects {
} }
} }
public static KeyValuePair<AbstractChange, AbstractChange[]> getNewAccountChanges(string _name, string password) { public static KeyValuePair<AbstractChange, AbstractChange[]> getNewAccountChanges(string _name, string password, string ip) {
string name = _name.Trim(); string name = _name.Trim();
checkNewName(name); checkNewName(name);
checkNewPassword(password); checkNewPassword(password);
@ -184,6 +185,7 @@ namespace FLocal.Common.dataobjects {
{ Account.TableSpec.FIELD_NEEDSMIGRATION, new ScalarFieldValue("0") }, { Account.TableSpec.FIELD_NEEDSMIGRATION, new ScalarFieldValue("0") },
{ Account.TableSpec.FIELD_PASSWORDHASH, new ScalarFieldValue(hashPassword(password, name.ToLower())) }, { Account.TableSpec.FIELD_PASSWORDHASH, new ScalarFieldValue(hashPassword(password, name.ToLower())) },
{ Account.TableSpec.FIELD_USERID, new ReferenceFieldValue(userInsert) }, { Account.TableSpec.FIELD_USERID, new ReferenceFieldValue(userInsert) },
{ Account.TableSpec.FIELD_IPADDRESS, new ScalarFieldValue(ip) },
} }
); );
var indicatorInsert = new InsertChange( var indicatorInsert = new InsertChange(
@ -204,8 +206,9 @@ namespace FLocal.Common.dataobjects {
); );
} }
public void migrate(string newPassword) { public void migrate(string newPassword, string ip) {
checkNewPassword(newPassword); checkNewPassword(newPassword);
if(!this.needsMigration) throw new FLocalException("Already migrated");
ChangeSetUtil.ApplyChanges(new AbstractChange[] { ChangeSetUtil.ApplyChanges(new AbstractChange[] {
new UpdateChange( new UpdateChange(
TableSpec.instance, TableSpec.instance,
@ -218,6 +221,10 @@ namespace FLocal.Common.dataobjects {
TableSpec.FIELD_NEEDSMIGRATION, TableSpec.FIELD_NEEDSMIGRATION,
new ScalarFieldValue("0") new ScalarFieldValue("0")
}, },
{
TableSpec.FIELD_IPADDRESS,
new ScalarFieldValue(ip)
},
}, },
this.id this.id
), ),

@ -84,11 +84,11 @@ namespace FLocal.Common.dataobjects {
} }
private object createAccount_locker = new object(); private object createAccount_locker = new object();
public Account createAccount(string code, string name, string password) { public Account createAccount(string code, string name, string password, string ip) {
lock(this.createAccount_locker) { lock(this.createAccount_locker) {
if(this.isUsed) throw new FLocalException("Invite is already used"); if(this.isUsed) throw new FLocalException("Invite is already used");
if(this.code != code) throw new FLocalException("Wrong code"); if(this.code != code) throw new FLocalException("Wrong code");
var rawChanges = Account.getNewAccountChanges(name, password); var rawChanges = Account.getNewAccountChanges(name, password, ip);
var accountInsert = rawChanges.Key; var accountInsert = rawChanges.Key;
var changes = new List<AbstractChange>(rawChanges.Value); var changes = new List<AbstractChange>(rawChanges.Value);
changes.Add( changes.Add(

@ -23,7 +23,7 @@ namespace FLocal.IISHandler.handlers.request {
string check = Util.md5(match.Groups[1].Value + " " + Config.instance.SaltMigration + " " + account.id); string check = Util.md5(match.Groups[1].Value + " " + Config.instance.SaltMigration + " " + account.id);
if(check != context.httprequest["check"]) throw new FLocalException("Wrong key (fhn:" + match.Groups[1].Value + ")"); if(check != context.httprequest["check"]) throw new FLocalException("Wrong key (fhn:" + match.Groups[1].Value + ")");
if(context.httprequest.Form["password"] != context.httprequest.Form["password2"]) throw new FLocalException("Passwords mismatch"); if(context.httprequest.Form["password"] != context.httprequest.Form["password2"]) throw new FLocalException("Passwords mismatch");
account.migrate(context.httprequest.Form["password2"]); account.migrate(context.httprequest.Form["password"], context.httprequest.UserHostAddress);
return account; return account;
} }

@ -17,7 +17,7 @@ namespace FLocal.IISHandler.handlers.request {
Invite invite = Invite.LoadById(int.Parse(context.httprequest.Form["inviteId"])); Invite invite = Invite.LoadById(int.Parse(context.httprequest.Form["inviteId"]));
if(invite.isUsed) throw new FLocalException("Invite is already used"); if(invite.isUsed) throw new FLocalException("Invite is already used");
if(context.httprequest.Form["password"] != context.httprequest.Form["password2"]) throw new FLocalException("Passwords mismatch"); if(context.httprequest.Form["password"] != context.httprequest.Form["password2"]) throw new FLocalException("Passwords mismatch");
return invite.createAccount(context.httprequest.Form["code"], context.httprequest.Form["login"], context.httprequest.Form["password"]); return invite.createAccount(context.httprequest.Form["code"], context.httprequest.Form["login"], context.httprequest.Form["password"], context.httprequest.UserHostAddress);
} }
} }

Loading…
Cancel
Save