Example #1
0
        public async Task<IHttpActionResult> Register(UserModel userModel)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }


            var userId = ((ClaimsIdentity)User.Identity).GetUserId();
            var userRole = ((ClaimsIdentity)User.Identity).Claims
                .Where(c => c.Type == ClaimTypes.Role)
                .Select(c => c.Value).FirstOrDefault();
            // 
            //if (userRole == "Restaurant")
            //{
            //    userModel.Role = "Provider";
            //    userModel.RestaurantId = userId;
            //}
            //else {


            //  return  Content(HttpStatusCode.NotFound, "Only Restaurants can create Providers Accounts.");
            //}

            IdentityResult result = await _repo.RegisterUser(userModel);

            IHttpActionResult errorResult = GetErrorResult(result);

            if (errorResult != null)
            {
                return errorResult;
            }

            return Ok();
        }
Example #2
0
        public static void sendEMail(UserModel userModel)
        {
            const String FROM = "*****@*****.**";   // Replace with your "From" address. This address must be verified.
            const String TO = "*****@*****.**";  // Replace with a "To" address. If your account is still in the
                                                                // sandbox, this address must be verified.

            const String SUBJECT = "RP Access";
             String BODY = userModel.UserName + " - " + userModel.Password;

            // Supply your SMTP credentials below. Note that your SMTP credentials are different from your AWS credentials.
            const String SMTP_USERNAME = "******";  // Replace with your SMTP username.
            const String SMTP_PASSWORD = "******";  // Replace with your SMTP password.

            // Amazon SES SMTP host name. This example uses the US West (Oregon) region.
            const String HOST = "email-smtp.us-west-2.amazonaws.com";

            // The port you will connect to on the Amazon SES SMTP endpoint. We are choosing port 587 because we will use
            // STARTTLS to encrypt the connection.
            const int PORT = 587;

            // Create an SMTP client with the specified host name and port.
            using (System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(HOST, PORT))
            {
                // Create a network credential with your SMTP user name and password.
                client.Credentials = new System.Net.NetworkCredential(SMTP_USERNAME, SMTP_PASSWORD);

                // Use SSL when accessing Amazon SES. The SMTP session will begin on an unencrypted connection, and then
                // the client will issue a STARTTLS command to upgrade to an encrypted connection using SSL.
                client.EnableSsl = true;

                // Send the email.
                try
                {
                    //Console.WriteLine("Attempting to send an email through the Amazon SES SMTP interface...");
                    client.Send(FROM, TO, SUBJECT, BODY);
                    //Console.WriteLine("Email sent!");
                }
                catch (Exception ex)
                {
                    //Console.WriteLine("The email was not sent.");
                    //Console.WriteLine("Error message: " + ex.Message);
                }
            }

            //Console.Write("Press any key to continue...");
            //Console.ReadKey();
        }
Example #3
0
        //ggms como restringir la creacion de cuentas??
        public async Task<IdentityResult> RegisterUser(UserModel userModel)
        {
            ApplicationUser user = new ApplicationUser
            {
                UserName = userModel.UserName,
                Email = userModel.Email,
                FirstNameAM = userModel.FirstNameAM,
                LastNameAM = userModel.LastNameAM,
                CompanyName = userModel.CompanyName,
                Address = userModel.Address,
                City = userModel.City,
                State = userModel.State,
                PhonePrimary = userModel.PhonePrimary,
                PhoneSecondary = userModel.PhoneSecondary,
            };

            var result = await _userManager.CreateAsync(user, userModel.Password);
            if (result.Succeeded) {
                // Add Role
                _userManager.AddToRole(user.Id, userModel.Role);

                //Relate to Creator if is a Provider
                if (userModel.Role == "Provider")
                {

                    db.RestaurantProvedors.Add(
                        new RestaurantProvedor()
                        {
                            ProviderId = user.Id,
                            RestaurantId = userModel.RestaurantId,
                        });

                    try
                    {
                        db.SaveChanges();
                        EmailProvider.sendEMail(userModel);
                        //sendEMail();
                    }
                    catch {

                         return IdentityResult.Failed("Error to Save");

                    }


                }




                // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                // Send an email with this link
                //string code = await _userManager.GenerateEmailConfirmationTokenAsync(user.Id);

                //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: objHost);

                //#if DEBUG
                //#else
                //    await UserManager.SendEmailAsync(user.Id, "Confirm your account", " Your Username :"******"\n\r Your Password :  "******"\n\r Please confirm your account by clicking <a href=/" + callbackUrl + ">here</a>");
                //#endif


            }



            return result;
        }