public void GetByEmail_Test() { // Act ThirdPartyUserService _svc = new ThirdPartyUserService(new Base64StringCryptographyService()); ThirdPartyUserLogin result = _svc.GetByEmail("*****@*****.**"); // Assert Assert.IsInstanceOfType(result, typeof(ThirdPartyUserLogin), "Must be login model"); //Assert.IsTrue(result > 0, "The insert result has to be greater the 0"); }
public ThirdPartyUserLogin GetByEmail(string Email) { ThirdPartyUserLogin model = null; this.DataProvider.ExecuteCmd( "ThridPartyUsers_GetByEmail", inputParamMapper delegate(SqlParameterCollection paramCol) { paramCol.AddWithValue("@Email", Email); } ); }
public HttpResponseMessage Login(LoginRequest 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>()); // checking for third party login ThirdPartyUserLogin check = _thirdPartyUserService.GetByEmail(model.Email); if (check.ThirdPartyTypeId > 0) { ErrorResponse resp = new ErrorResponse("Uncessful Login Attempt, user is registered with third party service"); return(Request.CreateResponse(HttpStatusCode.OK, resp)); } else { IUserAuthData success = _userService.LogIn(model.Email, model.Password); if (success != null) { List <int> pID = _userService.GetPerson(success.Id); LoginResponse <IUserAuthData> resp = new LoginResponse <IUserAuthData>(); resp.Item = success; resp.PersonID = pID; return(Request.CreateResponse(HttpStatusCode.OK, resp)); } else { ErrorResponse resp = new ErrorResponse("Uncessful Login 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)); } }
// [CREATE] public int Create(ThirdPartyUserLogin userModel) { int result = 0; string salt; string passwordHash; string password = userModel.Password; bool isConfirmed = true; bool isActive = true; 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("@Email", userModel.Email); paramCol.AddWithValue("@Pass", passwordHash); paramCol.AddWithValue("@Salt", salt); paramCol.AddWithValue("@isConfirmed", isConfirmed); paramCol.AddWithValue("@isActive", isActive); paramCol.AddWithValue("@FirstName", userModel.FirstName); paramCol.AddWithValue("@MiddleInitial", userModel.MiddleInitial); paramCol.AddWithValue("@LastName", userModel.LastName); paramCol.AddWithValue("@Location", userModel.Location); paramCol.AddWithValue("@ThirdpartyTypeId", userModel.ThirdPartTypeId); paramCol.AddWithValue("@AccountId", userModel.AccountId); }, returnParameters : delegate(SqlParameterCollection paramCol) { result = (int)paramCol["@Id"].Value; } ); return(result); }
public void InsertThirdPartyUserTest() { ThirdPartyUserLogin model = new ThirdPartyUserLogin(); model.Email = "*****@*****.**"; model.Password = "******"; model.FirstName = "FirstName"; model.MiddleInitial = "M"; model.LastName = "LastName"; model.Location = "http://www.industryexplorers.com/resources/Microsoft-logo_transparent.png"; model.CreatedBy = "API Unit Test"; model.ThirdPartyTypeId = 2; model.AccountId = "11111111111223243424233432"; // Act ThirdPartyUserService _svc = new ThirdPartyUserService(new Base64StringCryptographyService()); int result = _svc.Create(model); // Assert Assert.IsInstanceOfType(result, typeof(int), "Id has to be int"); Assert.IsTrue(result > 0, "The insert result has to be greater the 0"); }
public ThirdPartyUserLogin GetByEmail(string Email) { ThirdPartyUserLogin model = null; this.DataProvider.ExecuteCmd( "ThridPartyUsers_GetByEmail", inputParamMapper : delegate(SqlParameterCollection paramCol) { paramCol.AddWithValue("@Email", Email); }, singleRecordMapper : delegate(IDataReader reader, short set) { model = new ThirdPartyUserLogin(); int index = 0; model.UserId = reader.GetSafeInt32(index++); model.Email = reader.GetSafeString(index++); model.isConfirmed = reader.GetSafeBool(index++); model.isActive = reader.GetSafeBool(index++); model.ThirdPartyTypeId = reader.GetSafeInt32(index++); model.AccountId = reader.GetSafeString(index++); } ); return(model); }
public HttpResponseMessage SignIn(ThirdPartyUserLogin model) { try { //check if user exists ThirdPartyUserLogin check = _thirdPartyService.GetByEmail(model.Email); if (check == null) { //Register User int result = _thirdPartyService.Create(model); //If the registration does not work if (result == null || result <= 0) { ErrorResponse resp = new ErrorResponse("Unsuccessful Registration Attempt"); return(Request.CreateResponse(HttpStatusCode.OK, resp)); } //If succesfull, log the user in else { IUserAuthData success = _userService.LogIn(model.Email, model.Password); if (success != null) { List <int> pID = _userService.GetPerson(success.Id); LoginResponse <IUserAuthData> resp = new LoginResponse <IUserAuthData>(); resp.Item = success; resp.PersonID = pID; return(Request.CreateResponse(HttpStatusCode.OK, resp)); } else { ErrorResponse resp = new ErrorResponse("Uncessful Login Attempt"); return(Request.CreateResponse(HttpStatusCode.OK, resp)); } } } else //check for 3rd Party Type { if (check.ThirdPartyTypeId > 0) { IUserAuthData success = _userService.LogIn(model.Email, model.Password); if (success != null) { List <int> pID = _userService.GetPerson(success.Id); LoginResponse <IUserAuthData> resp = new LoginResponse <IUserAuthData>(); resp.Item = success; resp.PersonID = pID; return(Request.CreateResponse(HttpStatusCode.OK, resp)); } else { ErrorResponse resp = new ErrorResponse("Uncessful Login Attempt"); return(Request.CreateResponse(HttpStatusCode.OK, resp)); } } else { ErrorResponse resp = new ErrorResponse("Uncessful Login Attempt. User is already registered."); return(Request.CreateResponse(HttpStatusCode.OK, resp)); } } }//Mdoel State Valid catch (Exception ex) { log.Error(ex.Message, ex); return(Request.CreateResponse(HttpStatusCode.BadRequest, ex)); } }
// [CREATE] public int Create(ThirdPartyUserLogin userModel) { TransferUtility utility = new TransferUtility(awsS3Client); TransferUtilityUploadRequest request = new TransferUtilityUploadRequest(); var newGuid = Guid.NewGuid().ToString(""); var newFileName = "ThirdParty_ProfilePic_" + newGuid; string ProfileUrl = userModel.Location; var client = new WebClient(); var content = client.DownloadData(ProfileUrl); var stream = new MemoryStream(content); request.BucketName = bucketname; request.Key = newFileName; request.InputStream = stream; utility.Upload(request); userModel.Password = userModel.AccountId; int result = 0; string salt; string passwordHash; string password = userModel.Password; bool isConfirmed = true; bool isActive = true; 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( "ThirdPartyUsers_Register", inputParamMapper : delegate(SqlParameterCollection paramCol) { List <SqlParameter> parm = new List <SqlParameter>() { new SqlParameter("@UserId", SqlDbType.Int), new SqlParameter("@PersonId", SqlDbType.Int), new SqlParameter("@FileStorageId", SqlDbType.Int) }; foreach (var item in parm) { item.Direction = ParameterDirection.Output; } paramCol.AddRange(parm.ToArray()); paramCol.AddWithValue("@Email", userModel.Email); paramCol.AddWithValue("@Pass", passwordHash); paramCol.AddWithValue("@Salt", salt); paramCol.AddWithValue("@isConfirmed", isConfirmed); paramCol.AddWithValue("@isActive", isActive); paramCol.AddWithValue("@FirstName", userModel.FirstName); paramCol.AddWithValue("@MiddleInitial", userModel.MiddleInitial); paramCol.AddWithValue("@LastName", userModel.LastName); paramCol.AddWithValue("@FileTypeId", 1); paramCol.AddWithValue("@UserFileName", "ThirdParty_ProfileImg"); paramCol.AddWithValue("@SystemFileName", "ThirdParty_ProfileImg"); paramCol.AddWithValue("@Location", "https://sabio-training.s3.us-west-2.amazonaws.com/C53/" + newFileName); paramCol.AddWithValue("@CreatedBy", userModel.Email); paramCol.AddWithValue("@ThirdPartyTypeId", userModel.ThirdPartyTypeId); paramCol.AddWithValue("@AccountId", userModel.AccountId); }, returnParameters : delegate(SqlParameterCollection paramCol) { result = (int)paramCol["@UserId"].Value; } ); return(result); }