Ejemplo n.º 1
0
        public void Register(RegisterRequest model, string origin)
        {
            // validate
            var account = context.Accounts.Where(a => a.Email == model.Email).FirstOrDefault();

            if (account != null)
            {
                if (account.IsVerified)
                {
                    sendAlreadyRegisteredEmail(model.Email, origin);
                }
                else
                {
                    sendVerificationEmail(account, origin);
                }
                return;
            }

            // map model to new account object
            account = model.ToAccount();

            // first registered account is an admin
            account.Role = !context.Accounts.Any() ? Role.Admin : Role.User;
            account.VerificationToken = randomTokenString();

            // save account
            context.Accounts.Add(account);
            context.SaveChanges();

            // send email
            sendVerificationEmail(account, origin);
        }