Exemplo n.º 1
0
        //[Route("{guid:Guid}"), HttpPut]
        //public async Task<HttpResponseMessage> ResendConfirmationEmail(Guid guid)
        //{
        //    SecurityToken securityToken = SecurityTokenService.SelectByGuid(guid);

        //    ItemResponse<Guid> response = await SendNewConfirmationEmail(securityToken.FirstName, securityToken.LastName, securityToken.Email, securityToken.AspNetUserId);

        //    return Request.CreateResponse(HttpStatusCode.OK, response);
        //}

        private async Task <SuccessResponse> SendNewConfirmationEmail(string email, string id)
        {
            SecurityTokenAddRequest securityTokenAddRequest = new SecurityTokenAddRequest();

            securityTokenAddRequest.Email        = email;
            securityTokenAddRequest.AspNetUserId = id;

            SecurityToken securityToken = new SecurityToken();

            securityToken.TokenGuid    = SecurityTokenService.Insert(securityTokenAddRequest);
            securityToken.AspNetUserId = id;

            StringBuilder UrlBuilder = new StringBuilder(ConfigurationManager.AppSettings.Get("BaseUrl"));

            UrlBuilder.Append("/account/confirmemail?id=");
            UrlBuilder.Append(securityToken.AspNetUserId);
            UrlBuilder.Append("&token=");
            UrlBuilder.Append(securityToken.TokenGuid);

            await ExternalEmailService.ConfirmRegistration(UrlBuilder.ToString(), email);

            SuccessResponse response = new SuccessResponse();

            return(response);
        }
Exemplo n.º 2
0
        private async Task <ItemResponse <Guid> > SendNewConfirmationEmail(string firstName, string lastName, string email, string id)
        {
            SecurityTokenAddRequest securityToken = new SecurityTokenAddRequest();

            securityToken.FirstName    = firstName;
            securityToken.LastName     = lastName;
            securityToken.Email        = email;
            securityToken.TokenTypeId  = 1;
            securityToken.AspNetUserId = id;

            Guid emailSecurityToken = SecurityTokenService.Insert(securityToken);

            ConfirmationEmailRequest emailRequest = new ConfirmationEmailRequest();

            emailRequest.FirstName     = firstName;
            emailRequest.LastName      = lastName;
            emailRequest.Email         = email;
            emailRequest.SecurityToken = emailSecurityToken;
            //Removed static to enable DI
            await _emailService.ConfirmRegistration(emailRequest);

            ItemResponse <Guid> response = new ItemResponse <Guid>();

            response.Item = emailSecurityToken;
            return(response);
        }
Exemplo n.º 3
0
        private async Task <ItemResponse <Guid> > SendResetPasswordEmail(PersonBase pb, ConfirmationEmailRequest model)
        {
            SecurityTokenAddRequest securityToken = new SecurityTokenAddRequest();

            securityToken.FirstName    = pb.FirstName;
            securityToken.LastName     = pb.LastName;
            securityToken.Email        = model.Email;
            securityToken.TokenTypeId  = 2;
            securityToken.AspNetUserId = "";

            Guid emailSecurityToken = SecurityTokenService.Insert(securityToken);

            ConfirmationEmailRequest emailRequest = new ConfirmationEmailRequest();

            emailRequest.FirstName     = pb.FirstName;
            emailRequest.LastName      = pb.LastName;
            emailRequest.Email         = model.Email;
            emailRequest.SecurityToken = emailSecurityToken;

            await _emailService.ForgotPassword(emailRequest);

            ItemResponse <Guid> response = new ItemResponse <Guid>();

            response.Item = emailSecurityToken;
            return(response);
        }
Exemplo n.º 4
0
        public HttpResponseMessage Insert(SecurityTokenAddRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
            Guid response = new Guid();

            response = _svc.Insert(model);
            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
Exemplo n.º 5
0
        private async Task <SuccessResponse> SendResetPasswordEmail(String email)
        {
            SecurityTokenAddRequest securityTokenAddRequest = new SecurityTokenAddRequest();

            securityTokenAddRequest.Email        = email;
            securityTokenAddRequest.AspNetUserId = UserService.GetUser(email).Id;

            SecurityToken securityToken = new SecurityToken();

            securityToken.TokenGuid    = SecurityTokenService.Insert(securityTokenAddRequest);
            securityToken.AspNetUserId = UserService.GetUser(email).Id;

            StringBuilder UrlBuilder = new StringBuilder(ConfigurationManager.AppSettings.Get("BaseUrl"));

            UrlBuilder.Append("/account/resetpassword/");
            UrlBuilder.Append(securityToken.TokenGuid);

            await ExternalEmailService.ResetPassword(UrlBuilder.ToString(), email);

            SuccessResponse response = new SuccessResponse();

            return(response);
        }
Exemplo n.º 6
0
        public int Create(AccountUpsertRequest userModel)
        {
            int    userId = 0;
            string salt;
            string passwordHash;

            string password = userModel.Password;

            salt         = _cryptographyService.GenerateRandomString(RAND_LENGTH);
            passwordHash = _cryptographyService.Hash(password, salt, HASH_ITERATION_COUNT);

            _dataProvider.ExecuteNonQuery("dbo.Person_UpsertAccount",
                                          inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@Id", userModel.Id);
                paramCollection.AddWithValue("@FirstName", userModel.FirstName);
                paramCollection.AddWithValue("@LastName", userModel.LastName);
                paramCollection.AddWithValue("@Email", userModel.Email);
                paramCollection.AddWithValue("@Salt", salt);
                paramCollection.AddWithValue("@PasswordHash", passwordHash);
                paramCollection.AddWithValue("@RoleId", userModel.RoleId);
                //SqlParameter idParameter = new SqlParameter("@Id", SqlDbType.Int);
                //idParameter.Direction = ParameterDirection.Output;
                //paramCollection.Add(idParameter);
            }
                                          //,
                                          //returnParameters: delegate (SqlParameterCollection param)
                                          //{
                                          //    Int32.TryParse(param["@Id"].Value.ToString(), out userId);
                                          //}
                                          );

            //1)creating token
            SecurityTokenService    sts  = new SecurityTokenService(_dataProvider);
            SecurityTokenAddRequest star = new SecurityTokenAddRequest()
            {
                TokenTypeId = 1,
                UserEmail   = userModel.Email
            };

            System.Guid tokenGuid = sts.Insert(star);
            //2)emailing confirmation
            var source  = SiteConfig.BaseUrl;
            var message =
                "<body style='margin: 0; padding: 0; background:#ccc;'><table cellpadding=0 cellspacing=0 style='width: 100%;'><tr><td style='padding: 12px 2%;'><table cellpadding=0 cellspacing=0 style='margin:auto; background: #fff; width: 96%;'><tr><td style='padding: 12px 2%;'><div><h1 style='color:white;background-color:#1E90FF;'>Youth Mentoring Connection</h1></div > <div><h2 style='margin-top: 0;'>Congratulations</h2><p>You've successfully registered. Please confirm your email with Youth Mentoring Connection.To confirm your email click the link below:<br/></br> <span style='text-align:center; margin:0;'><a href="
                + source + "/confirmationPages?guid="
                + tokenGuid + ">Click Here To Confirm Email</a></p><p>...</p></div><div><h4 style='margin-top: 0;'>Sawubona!</h4><p></p></div><div style='border-top: solid 1px #ccc;'><p></p></div></td ></tr ></table ></td ></tr ></table ></body >";

            ConfirmationEmailService ces = new ConfirmationEmailService();
            ConfirmationEmailRequest cer = new ConfirmationEmailRequest()
            {
                From    = "*****@*****.**",
                To      = userModel.Email,
                Subject = "YMC Confirmation",
                Body    = message
            };
            Task <bool> email = ces.Execute(cer);

            return(userId);
            //DB provider call to create user and get us a user id
            //be sure to store both salt and passwordHash
            //DO NOT STORE the original password value that the user passed us
        }