Пример #1
0
        public static int InsertRegistration(RegistrationAddRequest model, string userId)
        {
            int id = 0;

            DataProvider.ExecuteNonQuery(GetConnection, "dbo.Users_Insert"   //this is the proc name
                                         , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@FirstName", model.FirstName);
                paramCollection.AddWithValue("@LastName", model.LastName);
                paramCollection.AddWithValue("@Phone", model.Phone);
                paramCollection.AddWithValue("@UserId", userId);

                SqlParameter p = new SqlParameter("@Id", System.Data.SqlDbType.Int);
                p.Direction    = System.Data.ParameterDirection.Output;

                paramCollection.Add(p);
            }, returnParameters : delegate(SqlParameterCollection param)
            {
                int.TryParse(param["@Id"].Value.ToString(), out id);
            }
                                         );


            return(id);
        }
Пример #2
0
        public HttpResponseMessage RegistrationAdd(RegistrationAddRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            try
            {
                IdentityUser user = UserService.CreateUser(model.Email, model.Password);

                UserService.InsertRegistration(model, user.Id);

                //_messagingService.SendConfirmationEmail(model, user.Id);

                return(Request.CreateResponse(user));
            }
            catch (IdentityResultException ire)
            {
                ErrorResponse er = new ErrorResponse(ire.Result.Errors);

                return(Request.CreateResponse(HttpStatusCode.InternalServerError, er));
            }
            catch (Exception e)
            {
                ErrorResponse er = new ErrorResponse(e.Message);

                return(Request.CreateResponse(HttpStatusCode.InternalServerError, er));
            }
        }
Пример #3
0
        public void Insert_Test()
        {
            // Arrange
            RegistrationAddRequest addRequestModel = new RegistrationAddRequest
            {
                Email    = "*****@*****.**",
                Password = "******",
            };
            // Act
            int result = _userService.Create(addRequestModel);

            // Assert
            Assert.IsInstanceOfType(result, typeof(int), "Id has to be int");
            Assert.IsTrue(result > 0, "The insert result has to be greater the 0");
        }
Пример #4
0
        public void Insert_Missing_DisplayName_Test()
        {
            // Arrange
            RegistrationAddRequest addRequestModel = new RegistrationAddRequest
            {
                //DisplayName = "Display Name 4",
                Password = "******",
            };

            // Act
            int result = _userService.Create(addRequestModel);

            // Assert
            Assert.IsInstanceOfType(result, typeof(int), "Id has to be int");
            Assert.IsTrue(result > 0, "The insert result has to be greater the 0");
        }
Пример #5
0
        public async Task <HttpResponseMessage> Post(RegistrationAddRequest model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var    webClient         = new WebClient();
                    string verification      = webClient.DownloadString(string.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", _configService.ConvertConfigValue_String("Google_Recaptcha"), model.recaptchaResponse));
                    var    recaptchaResponse = (JObject.Parse(verification)["success"].Value <bool>());

                    if (recaptchaResponse == true)
                    {
                        int id    = _userService.Create(model);
                        var email = model.Email;

                        var AuthTokenID       = _userService.AuthorizationToken(id);
                        var ConfirmationToken = AuthTokenID.ConfirmationToken;
                        var SendEmail         = _userService.GetEmail(ConfirmationToken, email);
                        int authTokenId       = _userService.CreateAuthToken(AuthTokenID);

                        ItemResponse <int> resp = new ItemResponse <int>();
                        var response            = await SendGridEmail.SendEmail(SendEmail);

                        return(Request.CreateResponse(HttpStatusCode.OK, resp));
                    }
                    else
                    {
                        ErrorResponse resp = new ErrorResponse("Uncessful Registration Attempt");
                        return(Request.CreateResponse(HttpStatusCode.OK, resp));
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState));
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.Message, ex);
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Пример #6
0
        // [CREATE]
        public int Create(RegistrationAddRequest userModel)
        {
            int    result = 0;
            string salt;
            string passwordHash;
            string password    = userModel.Password;
            bool   isConfirmed = false;
            bool   isActive    = false;

            salt         = _cryptographyService.GenerateRandomString(RAND_LENGTH);
            passwordHash = _cryptographyService.Hash(password, salt, HASH_ITERATION_COUNT);
            //DB provider call to create user and get us a user id
            this.DataProvider.ExecuteNonQuery(
                "Users_Insert",
                inputParamMapper : delegate(SqlParameterCollection paramCol)
            {
                SqlParameter parm  = new SqlParameter();
                parm.ParameterName = "@Id";
                parm.SqlDbType     = SqlDbType.Int;
                parm.Direction     = ParameterDirection.Output;
                paramCol.Add(parm);
                paramCol.AddWithValue("@FirstName", userModel.FirstName);
                paramCol.AddWithValue("@LastName", userModel.LastName);
                paramCol.AddWithValue("@Email", userModel.Email);
                paramCol.AddWithValue("@Pass", passwordHash);
                paramCol.AddWithValue("@Salt", salt);
                paramCol.AddWithValue("@isConfirmed", isConfirmed);
                paramCol.AddWithValue("@isActive", isActive);
            },
                returnParameters : delegate(SqlParameterCollection paramCol)
            {
                result = (int)paramCol["@Id"].Value;
            }
                );
            //be sure to store both salt and passwordHash
            //DO NOT STORE the original password value that the user passed us
            return(result);
        }
Пример #7
0
        public async Task <HttpResponseMessage> Register(RegistrationAddRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, string.Join(", ", ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage))));
            }
            try
            {
                if (model.DateOfBirth <= DateTime.MinValue)
                {
                    throw new ArgumentException("Please Select your Date of Birth");
                }
                IdentityUser user = _userService.CreateUser(model.Email, model.Password);

                if (user != null)
                {
                    RegistrationResponse response = new RegistrationResponse();
                    response.AspNetUserID    = user.Id;
                    response.Email           = model.Email;
                    response.MemberProfileId = _memberProfileService.Insert(new MemberProfileAddRequest
                    {
                        FirstName    = model.FirstName,
                        LastName     = model.LastName,
                        Email        = model.Email,
                        Gender       = model.Gender,
                        DateOfBirth  = model.DateOfBirth,
                        AspNetUserID = user.Id,
                        IsActive     = true,
                        IsPublic     = true,
                        IsViewable   = true
                    });

                    if (response.MemberProfileId > 0)
                    {
                        try
                        {
                            AppTokenResponse   tokenResponse = new AppTokenResponse();
                            AppTokenAddRequest tokenObject   = new AppTokenAddRequest()
                            {
                                MemberProfileId = response.MemberProfileId,
                                TokenTypeId     = (int)AppTokenType.ConfirmRegistration
                            };
                            tokenResponse.TokenGuid = _appTokenService.Insert(tokenObject);

                            await _sendEmailService.SendEmailRegConfirm(response.Email, tokenResponse.TokenGuid);

                            return(Request.CreateResponse(HttpStatusCode.OK, response));
                        }
                        catch
                        {
                            throw;
                        }
                    }
                }
                return(Request.CreateResponse(HttpStatusCode.OK, "Registration Success"));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }