Commit a2101772 authored by Andrei Mihu's avatar Andrei Mihu
Browse files

Return an error to the dev console when setting a password on a user account with no email.

parent 81b70120
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -476,11 +476,14 @@ AND ((facebook_id IS NOT NULL

		if len(newPassword) != 0 {
			// Update the password on the user account only if they have an email associated.
			_, err := tx.ExecContext(ctx, "UPDATE users SET password = $2, update_time = now() WHERE id = $1 AND email IS NOT NULL", userID, newPassword)
			res, err := tx.ExecContext(ctx, "UPDATE users SET password = $2, update_time = now() WHERE id = $1 AND email IS NOT NULL", userID, newPassword)
			if err != nil {
				s.logger.Error("Could not update password.", zap.Error(err), zap.Any("user_id", userID))
				return err
			}
			if rowsAffected, _ := res.RowsAffected(); rowsAffected != 1 {
				return StatusError(codes.InvalidArgument, "Cannot set a password on an account with no email address.", ErrRowsAffectedCount)
			}
		}

		if len(in.DeviceIds) != 0 && len(statements) == 0 && !removeCustomID && !removeEmail && len(newPassword) == 0 {