Generating admin user from the Seed() method - asp.net-mvc

I'm building a project where the user can access a CMS like admin system (I'm using the built in login that comes with MVC 4 projects). Each site will store the data in it's own SQL CE database. I want to publish the project without any existing db, and then let Entity Framework create it for me on the first hit.
The problem is that I can't let the /Account/Register method be [AllowAnonymous], so I need to have an already existing admin account in the "Users" table.
I want to have a "superuser" account that is already there when the db gets created, and then through this account I will log in and create a user account for the customer that is going to be using the CMS.
Is this possible, or do I need to drop this idea and just publish the project with an existing db?
If you have any other smart solutions, I'm all ears!? ;)
PS. The reason why I don't want to publish the site with a db is that I might accidentally overwrite any existing data if I do some bug fixes and forget to exclude the db from the project before deployment (for already existing sites etc).
I also have it set up so the Seed method fills the database with "starup" values, so the user starts with a clean slate.
Hopefully someone have any good ideas. I've tried searching but I couldn't really find what I was looking for.

Found the solution here:
http://kevin-junghans.blogspot.se/2013/01/seeding-customizing-aspnet-mvc.html
/ Mikael

Related

dynamically change schema for some tables in entity framework using db first with postgres

i am using entity framework 6 in my web api project which is database first EF with postgres.
we have say 10 tables, out of which say 5 are in central schema. but while login user select organization so on the basis of basis of that i want the other 5 tables to come from the some specific schema as per the organization selected(we have multiple schema containing same (say 5) table structure but different data)
while login i get the schema name so that is not the problem, but i want something to implement the above mentioned scenario.
Also the solution as mentioned in this awesome article
https://archive.codeplex.com/?p=efmodeladapter
is not acceptable in my project as we dont want to add anything in auto-generated file otherwise everytime we need to update that file manually whenever we do some update
Thanks in advance

Two Rails applications, one userbase, looking for a simplest solution to handle this

I have two Rails applications, let's call them A and B. A has existing user base and i want these users to be able to log in to B with the username and password managed in A.
B is altered version of Altered Beast forum and it would be nice if users of my application do not have to create another user account to use forum. My initial thought was just to swap out the User model with ActiveResource model. Forum is hosted on a different server so direct database connection to A's database is too much trouble.
My question is that is there any plugins or authentication system extensions that handle this kind of setup.
Altered Beast uses the restful_authentication plugin. Could you not just use the same plugin in application A pointed to the same database?
Edit:
Use a cooooooookies from application A.

Rails 2.1 and Rails 2.3 sharing the same database

We have an admin application used to manage member data and it was built in 2.1, has been running for about a year. Now that all inputs and data massage is done, our client wants to start building member site, members will have access to data the administrators have been inputting.
Here's the question, should we start a new Rails app hooked to the same admin database or should we create a new Rails app in different db with master-slave settings? The good thing about creating a new Rails app is obviously taking advantage of the new version, which we like. Or ..maybe just build the member site in the same admin app?
THanks,
Why don't you want to build the member site in the same admin app? Too much legacy?
You can use the same database but the problem is you will have to enforce any conditions you have in your models directly in your database (mandatory fields, model relationship and so on).
And I can see a lot of duplication code happening between the two apps. At least for the models. Which is really wrong :(
I don't recommend making two separate applications but It is hard to answer without looking at your app and without knowing more details.
Or build a new app using a copy of the existing database?
There's no reason the two applications cannot share the same database.
However, there's probably a number of reasons why they shouldn't. But, the only way you're going to figure those out are by going through the changelog of ActiveRecord's database adaptors.

How to turn a single-site app into a mantainable multi-site app without code changes?

It's an application that we use internally at the office that I would like to offer as a hosted service for anyone.
How can I do that without making major code changes?
The first thing that occurs to me is to have the app select which database to connect to based on the domain.
So each instance of the app would have its own database, but all instances would share the same code.
The only changes required to the code would be the database selection.
Is this approach maintainable? I've heard wordpress.com does this and that it offers a couple of advantages. I'm mainly looking to do it this way to avoid have to scope my entire set of database queries to a certain site within the same database.
Thanks!
The simplest way to do this is to clone the application, and create another server instance to handle it. This actually the way I handle multiple wordpress blogs on my server
Pro:
This process can be streamlined into a utility script.
Can be easily maintained if symlinks are used for the common code. IE: Everything but branding and some of the things in the config directory.
Cons:
- If you're using passenger it will require an apache restart for each new instance.
- Same if you're using Apache to route subdomains on different virtual hosts to different mongrel clusters.
However the better way comes from the question: Rails - Separate Database Per Subdomain
The method in the accepted answer is much more robust. It might require more changes than you're looking for, but it has all the benefits without the drawbacks of any other methods. Each new instance requires a new entry in the master database with the table name and other instance specific information. You'll also want custom rake task to build the database for each new instance.
I would suggest switching the database connection and adding a view_path based on the domain, I have posted code in this question.
I hope this helps!
I wouldn't do this with multiple databases as you mentioned. Keeping all your schemas/migrations in sync with all the db's could become painful.
I would look into simply making it a multi-tenant app where you have some sort of "Account" model and then all your existing models are scoped to it ... in other words, if this was a blog app, your Account has_many :posts, etc.
With this approach, you can identify accounts by subdomain ... have people choose their subdomain when they create an account and go from there.
It's pretty straightforward to do. If you need add billing into the mix, you might look at the SaaS Railskit (which handles all the signup and subdomain stuff) or Chargify.
You can also identify accounts Twitter-style ... with http://myapp.com/someuser

How do I change my user account domain in Team Foundation Server

We are migrating from one domain to another, and I'd like to be able to keep my same workspace, user settings, history, etc.
Is there any way to change just my domain or log in name within Team Foundation Server?
I don't know the answer, but I do know enough about TFS to be a little bit frightened about it.
If I understand you correctly, you want to change the domain that your users are authenticating as but you want to keep all the same user id's pointing to the same accounts in TFS?
TFS is highly integrated with Active Directory, and stores AD SID's around the place. It also is pretty sensitive to changes in the AD configuration.
I seem to remember one customer that I know of who has done this before, but I cannot find details of it now. I think that your best bet is to call Microsoft Product Support and raise a support incident about it as I have a vague memory that there was some special tool that had to be ran - but I could be mistaken.
Good luck,
Martin.
I know your login name is done through your Domain Controller but I dont know how that will work with switching which domain your TFS is on. Are you trying to move which domain the TFS installation is on or which domain your PC is on?

Resources