ASP.NET Membership.GetUserNameByEmail Error: “The E-mail supplied is invalid.”

April 13th, 2012 by comment

What the heck does this error message mean?? I had cause to find out when I was getting this error in a method that was simply updating the email address for an existing user. Mind you, I wasn’t creating a new user – I was just updating an existing user.  Since the error message is less than helpful, I thought I’d post this so anyone else getting this error won’t have to search as much as I did to find the solution.

Here’s how it came into play: I had created a secure web page to allow my client to manage some of their user accounts. They often had requests to change the email address for the account, so I created a simple form with a couple of text boxes (tbChangeEmail_Old and tbChangeEmail_New), a label to display the status of the attempt (lblChangeEmail_Status) and a Submit button.

Here’s the code I was using, when the user clicked the Submit button:

try
{
   string username = Membership.GetUserNameByEmail(tbChangeEmail_Old.Text);
   if (!string.IsNullOrEmpty(username))
   {
      MembershipUser user = Membership.GetUser(username, false);
      user.Email = tbChangeEmail_New.Text;
      Membership.UpdateUser(user);
      lblChangeEmail_Status.Text = "Email address successfully changed.";
   }
   else
   {
      lblChangeEmail_Status.Text = "Unable to find user with that email.";
   }
}
catch (Exception ex)
{
   lblChangeEmail_Status.Text = "Error: " + ex.Message;
}

It’s pretty straightforward – attempt to get the username using the ‘old’ email, and if the account isn’t found, display a message to the user. If we do find the username, then use it to get a MembershipUser object, set the Email property to the ‘new’ value, and update the user. Wrap that up in a try/catch block, and we’re good to go.

Everything worked fine, until today, when my client reported she was getting an error message for one user: “The E-Mail is invalid.” Huh. Did that mean the new email address wasn’t a valid email format? No, the new email was fine. Did it mean the old email didn’t work and the user wasn’t found? No, the test for !string.IsNullOrEmpty(username) catches that, and I verified that the account with the old email address was present. So what’s going on?

I did the usual trick of Googling for a solution, and found a lot of forum questions related to creating a new user, but then I finally found something about DUPLICATE emails, which, of course, are not allowed in the Membership database, based on our configuration. Aha! I did a quick SQL query of the DB, and sure enough, there was already an account with the ‘new’ email address, so it was not possible to update the ‘old’ account with the ‘new’ address!

So, since the existing error message is less than helpful in this case, I changed the logic in the catch block, so I could display a more helpful error on the web page:

catch (Exception ex)
{
   if (ex.Message.ToLower() == "the e-mail supplied is invalid.")
      lblChangeEmail_Status.Text = "There is another account with the 'new' email address, so the 'old' email account cannot be updated.";
   else
      lblChangeEmail_Status.Text = "Error: " + ex.Message;
}

Now, if we run across another case like this, my client will know exactly what’s going on. No more ambiguous error messages! J

So, not earth-shattering .NET stuff, but I figure what I learned might help someone else in the same situation. Happy coding!

ˆ Back to top

Displaying another app’s data using HTTParty and Kaminari

March 4th, 2012 by comment

I needed to access some data from another app and display it to users. The api side was a Rails 2.3.11 app and used will_paginate. It returned the json of a model collection and an association along with paginator information. The client side was a Rails 3.1 app using HTTParty and Kaminari.

API Controller

Rails 2.3.11 doesn’t include associations in the json, which is a known bug. So I returned a collection with the two models’ information. I used an API key to authenticate, which I won’t describe in detail since it’s outside the scope of this post.


class Api::FoosController < ApplicationController
  before_filter :authenticate_api_key!

  def foos_index
    @foos = Foo.paginate(:order => "created_at desc", :per_page => 40, :page => params[:page],
        :include => :bar)
    @records = @foos.collect { |foo| {:foo => foo, :bar => bar} }
    render :json =>  {:records => @records, :total_entries => @foos.total_entries,
        :per_page => @foo.per_page }
  end
end

API Route

The route requires the page number.


map.connect '/api/foos/foos_index/:page', :controller => "api/foos", :action => :foos_index

Client Model

FooIndex.foos_index returns itself, along with accessors for the response, records, total_count, current_page, and limit_value. The last three are important for Kaminari. When I parsed the JSON, I symbolized the keys. Much prettier than strings.


class FooIndex
  include HTTParty
  base_uri ENV['FOO_APP_URL']
  default_params :api_key => ENV['FOO_API_KEY']
  format :json
  attr_accessor :response, :records, :total_count, :current_page, :limit_value

  def initialize(response, records, total_count, current_page, limit_value)
    self.response = response
    self.records = records
    self.total_count = total_count
    self.current_page = current_page
    self.limit_value = limit_value
  end

  def self.foos_index(page)
    @current_page = page || 1
    response = get("/api/foos/foos_index/#{@current_page}")
    if response.success?
      json = JSON.parse(response.body, symbolize_names: true)
      self.new(response, json[:records], json[:total_entries], page, json[:per_page])
    else
      raise response.response
    end
  end
end

Client Controller

I had to be creative with Kaminari using the paginate_array method. The options total_count and limit are used because the api doesn’t return the whole set of data, just the data for one page.


class FoosController < ApplicationController
  def index
    params[:page] ||= 1
    @foos_index = FooIndex.foos_index(params[:page])
    @paginated_array = Kaminari.paginate_array(@foos_index.records,
        total_count: @foos_index.total_count,
        limit: @foos_index.limit_value).page(@foos_index.current_page)
  end
end

Client Route

Page number is optional in the route. The controller defaults it to page 1.


match '/foos(/:page)', :controller => :foos, :action => :index

Client View in HAML

The json returned by the api doubles up the first part of the hash. I’m not sure of an elegant way to handle that.


= paginate @paginated_array

%table
  %thead
    %th Foo Name
    %th Bar Name
    - @foos_index.records.each do |record|
      %tr
        %td= record[:foo][:foo][:name]
        %td= record[:bar][:bar][:name]

= paginate @paginated_array

And that’s all it takes. Please comment with any comments or questions.

ˆ Back to top

DevChix Speaking at Conferences 2012

March 3rd, 2012 by comment

We’ve collected a list of the DevChix speaking at conferences (so far) this year. If you are at one of these conferences, be sure to say hi!

January

February

March

April

May

June

July

ˆ Back to top

Meet devChix member Susan Potter

July 13th, 2011 by comment

Susan Potter is a wearer of many hats, but mostly software engineer and practicing applications architect (based in Chicago, IL).

Employer: Finsignia

Extras: Last month, Susan presented at WindyCityDB conference in Chicago, IL on Link-walking with Riak. She was a speaker at Code PaLOUsa 2011 in June. Talk: Deploying distributed software services to the cloud without breaking a sweat. She is very active in the open source community with GitHub personal repositoriesTwitter4R and collection of Gists.

Our short Q&A with Susan Potter:

What is your technical background?

At university I studied Mathematics, but audited Computer Science courses while writing an experimental parallel and distributed PDE solver first in C, then in C++ and finally in Java, which didn’t have much utility other than to teach me how not to write multi-threaded or distributed software.After graduating I worked for investment banks in London before skipping off to a San Francisco startup building a B2B trading platform and have since been working as a senior software consultant for hedge funds, investment banks and technology startups all over the US.

What industry sites or blogs do you read regularly?

To be honest, I use my Twitter timeline and some private lists as a fairly reliable source of interesting, relevant and/or thought-provoking technical resources from all over the internet. However, the following links have been fonts of recent software engineering wisdom or great resources in the areas I currently practice within:

What are a few of your favorite development tools and why?

I recently wrote a blog post on the (types of) tools that have made me a better software engineer. In short these are: emacs, vi(m), make, gdb, UNIX commands / utilities, UNIX shells, LaTeX, Git. The blog post explains why.

What tip or advice would you like to impart to women interested in programming?

If you enjoy software development, always learning new things and are excited about the possibilities in this field, then do not let anyone discourage you from persuing it further. There will always be a job market for self-starters that can teach themselves even if they don’t have the right educational background. Make sure to back up what you have learned on your own. Open source projects, blog posts or screencasts that demonstrate your skills in the areas you are looking to get into help much more nowadays than simply having a CS degree with no public portfolio IMHO.

If you were a computer part, what would you be?

A CPU socket comes close. It provides multiple connections (mechanical and electrical) between the microprocessor and circuit board. In the technology community it seems I am always connecting people based on their interests and needs such as connecting business founders with technical founders or hiring managers with skilled developers (mechanical connections). Other times I am suggesting new architectures, software stacks, tools, etc. to solve the problems people I talk to are currently encountering (electrical connections).

ˆ Back to top

Meet devChix member Aimee Daniells

June 2nd, 2011 by comment

aimee daniells (lowercase as requested) is a self-employed software crafter from Winchester, UK.

Her twitter handle: @sermoa and thoughts: http://sermoasquared.co.uk/

 

Our short Q&A with aimee daniells:

 

What is your technical background?

I was sponsored through university by IBM. I had an integrated degree where I worked at IBM 3 days a week and studied Computer Science at university 2 days a week. After I graduated I worked for IBM for a few years. Although I began as a developer, they decided to retrain me as a tester. I didn’t like the way IBM made decisions for me.

Now a tester, I looked for a job where I could begin as a tester but progress back into development. This didn’t really work. Fortunately I was learning in my spare time. I learned Ruby on Rails and made the application mychores.co.uk – a team based tracking system for recurring tasks. On the strength of that I got a job with Eden Development, an agile web development and consultancy company.

I worked at Eden for 3 years and took an apprenticeship under Enrique Comba Riepenhausen. I learned an incredible amount about good quality, reliable, well tested software and user experience design. Towards the end I took on two apprentices, one of whom I am still in regular contact with.

I am now an independent software crafter, doing freelance work and visiting companies to work as a contractor. I love what I do, I love meeting people and I love learning and sharing. At the last company I’ve just finished working at, I was approached by somebody who wanted to be mentored by me, who has now become my newest apprentice.

 

What industry sites or blogs do you read regularly?

I do not read RSS. I used to be subscribed to hundreds but I couldn’t read them all. These days I get all the news I need through twitter.

 

What are a few of your favorite development tools and why?

I love my macbook. It just does exactly what I want it to do, feels reliable and very rarely annoys me. I prefer to develop using Vim because I feel it is very powerful and I can express my intentions using intuitive combinations of keystrokes. I typed on the Dvorak keyboard layout for years, but I’ve recently changed to Colemak. I find it very comfortable and efficient to type on.

 

What tip or advice would you like to impart to women interested in programming?

Ask questions. Better to ask a silly question one day than give a silly answer another day. There is no such thing as silly questions, only silly answers. Listen a lot and ponder. Think carefully about what you believe. Share your opinions when asked. Share whatever you know. Be generous. Blog about things you find interesting: somebody else will do too. Ask for things you need. If you want to learn more, find a mentor. Don’t wait for people to do things for you. Make your own luck. Be extremely proud of who you are. Look yourself in the mirror every day and tell yourself how wonderful you are. Be humble. Don’t brag, but let your skills speak for themselves.

 

Last question on our q&a, if you were a computer part, what would you be?

I would be the Any key! :)

 

ˆ Back to top

Meet devChix member Nola Stowe

May 19th, 2011 by comment

Nola Stowe is a co-founder of devChix from the Texas, USA.
You can reach her at @rubygeekdotcom on twitter.
She is currently a web developer at Game Salad.
Game Salad is a free tool that creates games for the iPhone, iPad, Mac
& Web with no coding required.

Her linkedin: http://www.linkedin.com/in/nolastowe &
She blogs at RubyGeek.

 

Our short Q&A with Nola Stowe:

 

What is your technical background?

I started programming the summer I turned 13. I had a TRS-80 and read the BASIC programming book that came with it, along with another programming book I bought at Radio Shack. I had a cassette tape drive to save my files and a 5inc thermal printer. I programmed math games for my siblings. I distinctly remember making a program that would roll five dice and using ascii characters to draw  a box around the number. You could then choose which dice to re-roll. Ahh, sometimes I long for those summer days and also think: “…. boy, how much better I could have been if I had the internet like now!”

In college, I discovered the fun of web development so I majored in Computer Information System and Design Studio minor. I actually petitioned to have my water color class count towards my CIS degree, arguing that since my chosen field was web programming with a design minor, it is good to have the training and understanding of color principles from my water color class. They accepted my petition

 

What industry sites or blogs do you read regularly?

I check:

rubyinside.com – ruby is my favorite language; this is a great site to keep up with the ever-changing landscape

techcrunch.com – to keep up with what’s new with facebook, google, etc

railscasts.com – weekly screencasts, they are super informative

teachmetocode.com – screencasts on web development, very helpful

peepcode.com – screencasts at affordable prices, and great supporters of devChix.com

 

What are a few of your favorite development tools and why?

I use vim and textmate. It depends on the environment. For home development, I am on Ubuntu so I use Vim. For work, I use a Mac so I use both Vim and Textmate , but lately I’ve been using Textmate a lot.

 

What tip or advice would you like to impart to women interested in programming?

It’s a mans world for sure. Do not take it personally when someone gives you slack. Focus on doing the best work you can so people cannot tell the difference between your work and that of any other. Do not assume every issue you come across is “because you are a  girl” … just focus on what is needed to get the job done.

 

If you were a computer part, what would you be?

I would be a keyboard because I am always focusing on what is needed to get the job done. If we did not have keyboards, we would not be able to get much done. :)

 

ˆ Back to top

DevChix Speaking at Conferences 2011

May 4th, 2011 by comment

We’ve collected a list of the DevChix speaking at conferences (so far) this year. If you are at one of these conferences, be sure to say hi!

April

May

June

July

August

October

ˆ Back to top

Presenting at a start up conference for students

February 8th, 2011 by comment

This is an example of how devchix can work as a resource to connect events with developers.  If the organizers of this conference hadn’t reached out through this group I’d never have heard that it was happening, and I’m certainly glad I did.

Last weekend Greenhorn and Thoughtbot put on the D8 event (which stands for Developers x 4 & Designers x 4) at the Microsoft Research Center in Cambridge, MA.  It was a collection of 10 minute of presentations designed to introduce high school and college students interested in web design and/or development to the tools and workflow used by local start ups.  The website has lists of speakers and a collection of other resources for further reading on the topics presented. Read the rest of this entry »

ˆ Back to top

What makes the best workplace atmosphere and culture?

January 23rd, 2011 by comment

The DevChix community recently attacked the issue of what to do about a “blah” workplace environment. If you’ve done development for any length of time, or for more than a few companies, you’ve probably experienced the same thing somewhere along the way. Your coworkers are nice folks and everyone gets along, but there’s no real camaraderie. People work hard and produce good code, but no one seems too terribly excited about it. Sound familiar?

Lots of companies try to guard against this with perks meant to be fun and make work feel less formal. But sometimes all the kegerators in the world don’t make a difference. One of the DevChix described her experience in an office that sounds on paper like the Disneyland of workplaces:

“There are foosball tables, pool tables, air hockey tables and a beer keg in the kitchen. We work in quad-pods where there are 4 people in each large sized pod. The idea was to create a space open to collaboration. Nobody really talks much though. Things like the gaming tables are nice but I don’t see them having much impact. Some people grab a pint [from the keg] after 5pm and work at their desk, again not talking much. “

A “neutral” company culture, it seems, is not a problem you can just throw a couple foosball tables at. The DevChix suggested the problem is rooted in how a company treats its devs.

Where does uninspiring culture begin?

If you guessed “management”, the list agrees with you (at least partially). Developer empowerment was highlighted as one of the biggest things that make a difference in developers’ passion at work. Without realizing it, managers may be making their developers feel isolated or ignored:

“Management might be thinking that what they’re working on isn’t that relevant to their staff, or is relevant but they haven’t made significant enough progress to share – but communicating the use of your time, however vaguely, on a regular basis has a way of clearing the air.  It says, “I’m not forgetting about you” and also promotes open communication (when I’m not hearing anything from a manager, I don’t feel as comfortable going to him or her with my problems).  I’ve been surprised at how strong of a reaction seeing upper management going in and out of meetings without sharing any details whatsoever has had on me, and it’s not even that I want to have a lot of data.”

Another problem can be the ways in which developers are encouraged to interact. If collaboration is rare, developers have less to talk about as developers. The extroverted ones will probably find other things to discuss around the water cooler, but if they aren’t working together, it’s likely that company culture is repressing the urge to share ideas over the cubicle wall. It’s important to consider how many developers are likely to be introverts – development, after all, isn’t sales – and leave a space for interaction at work that isn’t so unstructured that it exhausts anyone or excludes them. In short, aimless chatter can be tiring or distracting, but active teamwork is inspiring.

What can companies do differently?

One of the more unanimous suggestions was to offer developers the opportunity to do non-business-driven projects. Giving teams the opportunity to use new technologies, proof of concept the things they think are important, and generally develop something to their own standards gives developers a voice in what they’re doing. Google’s 20% time was offered as an example of this. Having a policy like this and promoting it as aggressively as Google does creates an impression of a place where developers’ ideas are sought out and supported, even in outsiders. And supporting developer-driven projects doesn’t mean simply tolerating them. The DevChix who gave examples of similar projects they’d worked on mentioned that these – in whole or in part – had eventually been used by their employers in “normal” projects.

Something that was new to me was the idea of project leads bidding on resources to give developers more control over what they’re working on (a project owner could say, “I need this done but it’s the only thing I need done this sprint,” if I understand correctly). At a busy agency or a start-up just getting its feet under it, committing 20% of each developer’s time to projects that might turn out to be technically infeasible might be too expensive. Letting developers choose their projects would be a great alternative.

Toward the end of promoting camaraderie and sharing knowledge, something developers might be able to do without having to get management approval is peer code reviews. This is certainly more challenging when everyone is working on a separate project, but consider that not everyone has to share all their code all the time. The woman who suggested this mentioned that her team had one or two people presenting once a week, something that should be manageable no matter how many different projects a dev team was working on.

A simple but important suggestion that was brought up by different people with different examples was offering developers the chance to “learn something cool”. This could be done by in-office trainings, brown bag lunches, or sending developers to conferences, but the DevChix who mentioned it seemed to agree that it’s a big part of getting developers excited. These can range in cost to the company all the way up to (and occasionally past) $2k, but consider what the employer gets in return:

“It was amazing how [attending a conference turned] jaded, tired corporate workers into ra-ra cheerleaders like overnight. The amount of info you can get at these things – along with connections of course – is intense. And it’s great to show that the corporation is willing to invest in the employee.”

If a company can’t spend the money on conference registration, air travel, and a hotel stay for an employee, they could also try to bring the expertise to the developers. It was pointed out that many technical leaders are happy to share an hour of their time, and this gives everyone on the team the chance to learn together instead of one or two people getting to go to a conference while the rest of the team is back at the office park slaving away. If a company is so isolated that the only way to boost developer knowledge is through sending employees out of town for conferences, one suggestion was to give the rest of the dev team the same time off their peer attending the conference was getting to read, learn, and work on exciting proofs of concept.

In summary, the DevChix who participated in this thread emphasized the need to treat smart, valuable people like smart, valuable people, whether you manage them or sit next to them. One nice thing about developers is that you don’t really need a foosball table to get them excited about coming into the office – generally you just need to give them the freedom to do what they love: write good code.

ˆ Back to top

RailsBridge Open Workshop Project

January 18th, 2011 by comment

Wow so many workshops!  I will be helping run the Chicago one on the weekend of Feb. 4-5th details are at the bottom of this press release. Be sure to tell others or volunteer!  We could also use sponsors so if any one would like to donate just email me directly. desi.mcadam at gmail

RailsBridge Open Workshop Project Announces Workshops for 2011

SAN FRANCISCO, Calif. — The RailsBridge Open Workshop project, which teaches web application development to both programmers and non-programmers, is announcing eight more of its popular free workshops for women in 2011.

The project, which has trained almost 600 people, nearly 500 of them women, in five cities in the past year and a half, is gaining speed in 2011.  RailsBridge has planned eight workshops so far, mostly in San Francisco, but branching out to the north bay, as well as Chicago and Seattle.

Read More..

Workshops Confirmed for 2011

The following workshops have confirmed venues and leaders.  Several additional workshops are also in the planning stages:

February 4-5, Twitter, San Francisco, led by Amy Chen (already full)

February 4-5, Hashrocket, Chicago, led by Desi McAdam – Attendees Meetup Page Volunteers Meetup Page:

March 11-12, Enphase Energy, Petaluma, led by Brenda Strech & Ilen Zazueta-Hall (meetup)

April 7-8, ModCloth, San Francisco, Megan Guering

April, White Pages, Seattle, Elise Worthy

May 6-7, SoMA Central, San Francisco, led by Andrea Ängquist and Raphael Lee

July 15-16, Miso, San Francisco, Amy Lightholder, Rachel Myers

August 5-6, Quid, San Francisco, Andrea Angquist, Walter Y

ˆ Back to top

cheap research papers