/// <summary> /// Creates a user and adds to database /// </summary> /// <returns>Result of registration</returns> internal static RegisterResult CreateUser(string email, string username, string fullname, string password, DateTime birthdate) { if (Users.FindByEmail(email) != null) { return(RegisterResult.EmailTaken); } if (Users.FindByUsername(username) != null) { return(RegisterResult.UsernameTaken); } Users u = new Users() { Email = email, UserName = username, FullName = fullname, BirthDate = birthdate, Registered = DateTime.Now, LastLogin = DateTime.Now, Coins = 0, ByteDollars = 0, TotalExp = 0, AccessLevel = AccessLevel.Unconfirmed }; u.UpdatePassword(password); using (DataContext db = new DataContext()) { db.Users.Add(u); db.SaveChanges(); Debug.WriteLine("User creation attempted"); Users createduser = Users.FindByEmail(email, db); createduser.UserKeyStore = KeyStore.DefaultDbKeyStore(password, createduser.Salt, createduser.UserID); UserIPList uip = new UserIPList(); uip.UserId = createduser.UserID; uip.UserIPStored = GetIP(); db.UserIPList.Add(uip); db.SaveChanges(); if (createduser is Users) { EmailConfirm.SendEmailForConfirmation(createduser, db); Machines.DefaultMachine(createduser, db); ItemLogic.StoreDefaultParts(db, u.UserID); AuthLogger.Instance.UserRegistered(u.Email, u.UserID); return(RegisterResult.Success); } else { throw new RegistrationException("User cannot be registered due to an error (NOT_TYPE_USER)"); } } }